SQL - Conditional Terms in WHERE part of SQL Statement

  • Thread starter Thread starter Bob T
  • Start date Start date
B

Bob T

Hello,

I am trying to create a somewhat complex SQL statement with many possible
WHERE components. So far I have used If...ELSE statements and rewritten the
entire SQL statements with variations. Is there a way to have conditional
terms as part of the WHERE statements? I have tried various forms of CASE
and have not been able to compile.

Robert
 
What DB are you using? If you are using SQL Server you can use Case, if
Oracle, Decode.

If Access, time to move up to MSDE ;-).

Can you post the snippet,I could probably be of more help then.

Cheers,

Bill
 
Hi Bob,

I doubt that you can use case for switching between fields in WHERE clause.
You can choose only between values, IMO, something like (northwind):

select * from customers where customerid = case region when null then
'alfki' else 'anatr' end

It should be the same for Oracle.
 
Back
Top