Question : Conditional where clause

Hello,

I'm having a problem where I have a WHERE-clause which depends on input from the user.

My first thought was something similar to the switch-statement you find in some languages but I can't seem to find anything similar.

A CASE is not acceptable since that returns a value and I need to set conditions. And I cannot use stored procedures or similar either; it all has to be done in a SELECT.

Anyone got any ideas? See pseudo-code below.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
SELECT
	something
FROM
	somewhere
WHERE
	switch(input)  {
		case 100:
			field1 = input
			break;
		case 101:
			field1 = input OR field1 = 200
			AND
			field2 IN (1,2,3)
			break;
		case 102:
			field1 = input
			AND
			field2 IN (2,5,7)
			break;
		case 103:
			field1 = input
			break;
	}
Open in New Window Select All

Answer : Conditional where clause

yes, use case like this...


SELECT something
  FROM somewhere
 WHERE CASE
           WHEN input = 100 AND field1 = input THEN 1
           WHEN input = 101 AND (field1 = input OR field1 = 200 AND field2 IN (1, 2, 3)) THEN 1
           WHEN input = 102 AND field1 = input AND field2 IN (2, 5, 7) THEN 1
           WHEN input = 103 AND field1 = input THEN 1
           ELSE 0
       END = 1
Random Solutions  
 
programming4us programming4us