Can any help on the below Query in the where statement in T-SQL?
I have ID & Product fields in table,in where condition need to exclude the ID not in(’11’,’22’,’33’) only when for Product=’c’
Select ID,Product from Supplier where 1=1 and Product in('A','B','C')
The statment should present
and ID not in('11','22','33')
Expecting when the Product=’C’, exclude the ID
Advertisement
Answer
You can try this
Select ID, Product from Supplier where 1=1 and ( Product in('A','B') OR ( Product = 'C' AND ID not in('11','22','33')) )