constructing dynamic In Statements with sql

Posted by nitroxn on Stack Overflow See other posts from Stack Overflow or by nitroxn
Published on 2010-03-15T15:39:48Z Indexed on 2010/03/15 16:39 UTC
Read the original article Hit count: 253

Filed under:
|
|

Suppose we need to check three boolean conditions to perform a select query. Let the three flags be 'A', 'B' and 'C'.

If all of the three flags are set to '1' then the query to be generated is SELECT * FROM Food WHERE Name In ('Apple, 'Biscuit', 'Chocolate'); If only the flags 'A' and 'B' are set to '1' with C set to '0'. Then the following query is generated.

SELECT * 
  FROM Food 
 WHERE Name In ('Apple, 'Biscuit');

What is the best way to do it?

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql