user3505449 user3505449 - 1 year ago 74
SQL Question

IN() function with multiple parameter

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


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.


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 Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download