Possible Duplicate:
Parameterizing a SQL IN clause?
In SQL Server I'd like to do something to this effect...
DECLARE @Values varchar(1000)
SET @Values = 'A, B, C'
SELECT
blah
FROM
foo
WHERE
myField IN (@Values)
Is this possible or how to accomplish this?
You need a table variable:
Ideally you shouldn't be splitting strings in T-SQL at all.
Barring that change, on older versions before SQL Server 2016, create a split function:
Now you can say:
On SQL Server 2016 or above (or Azure SQL Database), it is much simpler and more efficient, however you do have to manually apply
LTRIM()
to take away any leading spaces:Use a Temp Table or a Table variable, e.g.
and then
or