user3505449 user3505449 - 4 months ago 9
SQL Question

IN() function with multiple parameter

When I am set parameter as in following way the not getting properly result.

Query:

SET @parmClientList ='7,11,14';

Select fkUserID from tbluserclient where MultipleClientID IN(@parmClientList);


but when I declare directly as hard coded then I getting proper result.

Query:

select fkUserID from tbluserclient where MultipleClientID IN(7,11,14);


Can some one suggest me how to pass multiple value to IN() function parameter.

Answer

The list in the IN() condition has to be a literal list, it won't split a string. Use FIND_IN_SET()

SELECT fkUserID FROM tbluserClient
WHERE FIND_IN_SET(MultipleClientID, @parmClientList);
Comments