Pass comma separated variable to IN clause in SQL Server

Last Reply one month ago By pandeyism

Posted one month ago

hi

i want to pass a list of values string like in a dinamic query

DECLARE @Lines AS NVARCHAR(MAX)

SET @Lines = 'PL1,PL2,PL3'

SET @Query = '

WHERE ProductLines IN (@Lines) ...'

How can do that?

You are viewing reply posted by: pandeyism one month ago.
Posted one month ago

Hi jon,

Refer below link to split value using comma.

Insert Comma Separated (Delimited) values in a Table in SQL Server

Refer below query.

SQL

DECLARE @Lines AS NVARCHAR(MAX)
SET @Lines = 'USA,UK'
SELECT * FROM Customers
WHERE Country IN ( SELECT Item FROM SplitString(@Lines,','))