BioHolic
BioHolic

Reputation: 21

Oracle SQL different where clauses with case when

stupid question, cause I want to start a select statement with two options of where clauses and stuck in the part where I can filter it. The problem is, that I want the option to say "if RS_BEM is A1 or A2 then search for ID that are not in the list, if anything else search for ID that are in the list".

and Case when :RS_BEM like 'A1' or :RS_BEM like 'A2' then ate_msg_nr not in (select * from StoerIDs) else ate_msg_nr in (select * from StoerIDs) end

I bet it's super easy but somehow I don't see it.

Upvotes: 0

Views: 37

Answers (1)

Thorsten Kettner
Thorsten Kettner

Reputation: 95052

Use AND, OR, and parentheses:

where (:RS_BEM in ('A1', 'A2') and ate_msg_nr not in (select * from StoerIDs))
   or (:RS_BEM not in ('A1', 'A2') and ate_msg_nr in (select * from StoerIDs))

Upvotes: 3

Related Questions