SQL - Conditional Terms in WHERE part of SQL Statement

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
 
W

William Ryan

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
 
M

Miha Markic

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top