SQL - Conditionally evaluate WHERE clauses

Posted by Crimius on Stack Overflow See other posts from Stack Overflow or by Crimius
Published on 2010-04-09T12:51:29Z Indexed on 2010/04/09 12:53 UTC
Read the original article Hit count: 171

Filed under:
|
|

I need to get a WHERE clause to only evaluate certain statements. something like:

WHERE field_a = field_b AND
   (CASE WHEN <PARAM>type</PARAM> = 5
      THEN {field_c = 1 OR field_c = 2}
      WHEN <PARAM>type</PARAM> = 6
      THEN {field_c = 3 OR field_c = 4}
      ELSE field_c = <PARAM>type</PARAM>

so that when the Param type = 5, it only checks if field_c = 1 or 2. Any thoughts?

© Stack Overflow or respective owner

Related posts about sql

Related posts about if