|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WHERE Clause CASEThe 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 Scott wrote:
> The below WHERE clause in CODE 1 works fine, but gives me a null error if Assuming time_run and time_run2 are the same datatypes:> 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? WHERE CASE mill_id WHEN 1 THEN time_run WHEN 2 THEN time_run2 END IS NOT NULL |
|||||||||||||||||||||||