Possible Duplicates:
Parameterizing a SQL IN clause?
SQL Server SP - Pass parameter for “IN” array list?
I need to search for a haphazard set of integers on two different tables:
SELECT
col_1, col_2
FROM
LIKES_NUMBERS
WHERE
col_1 IN (1,2,3,5,7,1021,10041411)
SELECT
col_one, col_two
FROM
LIKES_NAMES
WHERE
col_one IN (1,2,3,5,7,1021,10041411)
Is there a SQL list type that can be passed to IN so that I don't repeat myself? E.G.
DECLARE @stuff UNOBTAINIUM(1,2,3,5,7,1021,10041411)
-- ...
WHERE col_1 IN (@stuff)
-- ...
WHERE col_one IN (@stuff)
Creating a temporary table comes to mind, but that seems brutal.
Yes, you can use a table variable for this. It's like a temp table, but locally scoped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With