0

Wanna search for all rows where TAX = 'asd' if PARAM equals 1, else all rows where TAX <> 'asd' (every row that isn't 'asd').

Something like this:

WHERE
  TAX (
     CASE
        WHEN PARAM = '1'
           THEN = 'asd'
        ELSE <> 'asd'
     END)
Matt
  • 14,906
  • 27
  • 99
  • 149
  • It's generally a bad idea to use `case` expressions in `where` clauses. Use `AND`/`OR` constructions instead. – jarlh Sep 11 '18 at 12:22

4 Answers4

4

You can add where clause with Boolean logic :

WHERE (PARAM = 1 AND TAX = 'asd') OR
      (PARAM <> 1 AND TAX <> 'asd');

If, the PARAM has NUMERIC type, then you don't need to include ' '.

Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
1

No need for a CASE statement just use brackets and OR.

SELECT *
FROM yourtable
WHERE (TAX = 'asd' AND PARAM = '1') OR (TAX != 'asd')
Matt
  • 14,906
  • 27
  • 99
  • 149
0
SELECT *
FROm table
WHERE (TAX = 'asd' AND PARAM IN (1))
OR (TAX <> 'asd' AND PARAM NOT IN (1))
Mazhar
  • 3,797
  • 1
  • 12
  • 29
0

This can be achieved with OR, AND and some brackets:

WHERE (PARAM = 1 AND TAX = 'asd')
OR (TAX <> 'asd')

Be sure to consider cases where TAX may be NULL, unless that is explicitly prohibited by your database design.

FiddleStix
  • 3,016
  • 20
  • 21