Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditionally set values passed to IN operator

Status
Not open for further replies.

thermidor

Programmer
Nov 28, 2001
123
US
Hi All:

I want to write a query to conditionally set the values passed to an IN operator. Using the code below, I want to pass ('A', 'B') when someVariable = 'someVal'. Else I pass ('C', 'D', 'E'). Whatever I pass should filter the cur_data table on the key_letter column.

Any thoughts how to do this?

TIA,
Sven

SELECT colA FROM cur_data
WHERE key_letter IN
(CASE WHEN someVariable = 'someVal'
THEN ('A', 'B')
ELSE ('C', 'D', 'E')
END)
 
Thanks for the pointer Dagon. SantaMufasa has helped me many times!
 
You could also do the following


SELECT colA FROM cur_data
WHERE (someVariable = 'someVal' and key_letter IN ('A','B'))
or (someVariable <> 'someVal' and key_letter IN ('C', 'D', 'E'));

Bill
Lead Application Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top