Lets say I have a SQL table that has the id's 1
through 30
but I want to exclude the numbers 7,10,21 from the sql.
How would I do this without writing something like
SELECT *
FROM TBL
WHERE COL <> '7' AND COL <> '10' AND COL <> '21'
But instead, write something like
SELECT *
FROM TBL
WHERE COL NOT IN (@IDS)
When trying the example, it works if @IDS
is equal to one number, but if it is equal to multiple numbers all records show.
To clarify the reason it has to be a list of numbers is that is how it is passed to the SQL. I am unable to change how the data is passed.
To clarify more because I should have stated it in the original question. I do not know the exact numbers being passed into the SQL Statement, the ones I provided were for the example, but it could be any number.