January 28, 2016 at 9:36 am
Hi Team,
I have the below requirement my table has the below data
TABLENAME - SOURCE
EMPID ENAME DEPARMENT
1 XXX IT
2 YYY SALES
3 ZZZ MARKETING
4 OOO COMPUTERS
EXPECTED OUTPUT
EMPID IT SALES MARKETING COMPUTERS
1 XXX NULL NULL NULL
2 NULL YYY NULL NULL
3 NULL NULL ZZZ NULL
4 NULL NULL NULL OOO
January 28, 2016 at 11:14 am
sqlfriends@sql.com (1/28/2016)
Hi Team,I have the below requirement my table has the below data
TABLENAME - SOURCE
EMPID ENAME DEPARMENT
1 XXX IT
2 YYY SALES
3 ZZZ MARKETING
4 OOO COMPUTERS
EXPECTED OUTPUT
EMPID IT SALES MARKETING COMPUTERS
1 XXX NULL NULL NULL
2 NULL YYY NULL NULL
3 NULL NULL ZZZ NULL
4 NULL NULL NULL OOO
Just use a CASE statement for each column without aggregates.
SELECT EMPID, CASE WHEN DEPARTMENT = 'IT' THEN ENAME END, ...
FROM TABLE;
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply