all groups > sql server programming > august 2006 >
You're in the

sql server programming

group:

WHERE Clause CASE


Re: WHERE Clause CASE Chris Lim
8/19/2006 4:47:15 PM
sql server programming: [quoted text, click to view]

Assuming time_run and time_run2 are the same datatypes:

WHERE CASE mill_id
WHEN 1 THEN time_run
WHEN 2 THEN time_run2
END IS NOT NULL
WHERE Clause CASE Scott
8/19/2006 6:34:27 PM
The below WHERE clause in CODE 1 works fine, but gives me a null error if
mill_id = 2. That's because the WHERE clause should look CODE 2 when mill_id
= 2.

Is there a way to use the CASE function in the WHERE clause to test the
mill_id variable and use "AND time_run2 IS NOT NULL" if mill_id = 2 and "AND
time_run IS NOT NULL" if mill_id = 1?


CODE 1 *****************
WHERE mill_id = 1 AND time_run IS NOT NULL



CODE 2 *****************
WHERE mill_id = 2 AND time_run2 IS NOT NULL

AddThis Social Bookmark Button