Answer the question
In order to leave comments, you need to log in
How to filter a table by a column whose value is included / not included in the list of values?
When generating SQL from code, only one condition line is available
SELECT * FROM [dbo].[data] WHERE ([dbo].[data].[intField] IN (0,1,2,8,9))[email protected]
([dbo].[data].[intField] IN (0,1,2,8,9)
- this piece Answer the question
In order to leave comments, you need to log in
Option 1:
Sew NOT into the query text, depending on the state of p1:
"SELECT * FROM [dbo].[data] WHERE ([dbo].[data].[intField] " + (p1 ? "" : "NOT") + " IN (0,1,2,8,9))"
SELECT * FROM [dbo].[data]
WHERE @p1 = true and [dbo].[data].[intField] IN (0,1,2,8,9)
or @p1 = false and [dbo].[data].[intField] NOT IN (0,1,2,8,9)
SELECT * FROM [dbo].[data]
WHERE @p1 = 0 and [dbo].[data].[intField] IN (0,1,2,8,9)
or @p1 = 1 and [dbo].[data].[intField] NOT IN (0,1,2,8,9)
SELECT *
FROM [dbo].[data]
WHERE ( @p1 = 0 AND [dbo].[data].[intField] NOT IN (0,1,2,8,9) )
OR ( @p1 = 1 AND [dbo].[data].[intField] IN (0,1,2,8,9) )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question