Sql-server – Set variable with multiple values and use IN

sql-servertsql

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?

Best Solution

You need a table variable:

declare @values table
(
    Value varchar(1000)
)

insert into @values values ('A')
insert into @values values ('B')
insert into @values values ('C')

select blah
from foo
where myField in (select value from @values)