I have requirement where in value of three columns depend on the value of single column . Say I have a table as
A | B | C | D | E
A,B,C,D and E are the columns and requirement is to get values of A,B and C as such if the value of column D is '1' else the values for A,B and C will be NULL.
I tried using CASE statement but it seems like we have to use CASE multiple times
SELECT
CASE
WHEN D = '1'
THEN A
ELSE NULL,
CASE
WHEN D = '1'
THEN B
ELSE NULL;
I was looking for something like just one CASE and select the appropriate values. Is there some way we can achieve that or this is the recommended way.
CASEexpression; SQL Server doesn't supportSwitch(CaseStatements)ELSE NULLas that is the default