Reputation: 11
How to pass a comma separated text to a where condition. I have a query scenario like below
select *
from employees
where employeeid in ('PER5AZ,SF4MDD,WQERR') -- This will not work
Here I need to filter the employeeid
by PER5AZ, SF4MDD and WQERR which I get as a comma separated string from front end.
How to do this in SQL Server 2016?
Upvotes: 0
Views: 3211
Reputation: 1813
try this using STRING_SPLIT function.
select *
from employees
where employeeid in (select value from STRING_SPLIT ('PER5AZ,SF4MDD,WQERR', ','))
Note: STRING_SPLIT works SQL server 2016 or above
Upvotes: 2