tmajor99
asked on
SQL Select to conditionally set a column to null based on a value from another column
I need a conditional SQL Select. I need to conditionally set a column to null based on the value of another column. For example;
Table
ID Shelf Life Flag Shelf Life Days
------------- --------------- -----------------
100 Y 10
200 N NULL
300 (blank) NULL
I need to set the Shelf Life Days column to NULL if Shelf Life Flag is set to "Y".
Table
ID Shelf Life Flag Shelf Life Days
------------- --------------- -----------------
100 Y 10
200 N NULL
300 (blank) NULL
I need to set the Shelf Life Days column to NULL if Shelf Life Flag is set to "Y".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SELECT A.[Batch ID], A.[Shelf Life Days]
, CASE A.[Lot Control]
WHEN 'Y' THEN [Shelf Life Days]
ELSE NULL
END [Lot Control],
CASE A.[Lot Control]
WHEN 'Y' THEN [Shelf Life Days]
ELSE NULL
END [Shelf Life Days]
from [EGP_SYSTEM_ITEMS_INTERFAC
Please ignore the syntax differences.