Home All Groups Group Topic Archive Search About
Author
19 Aug 2006 11:34 PM
Scott
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

Author
19 Aug 2006 11:47 PM
Chris Lim
Scott wrote:
> 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?

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

AddThis Social Bookmark Button