Can someone help me with the SQL query using the below data?
Whenever I see the type as deactivating irrespective of other types in same-ID I have to get only deactivate values and the rest of values should be null.
select id,
pid,
type,
case when type='deactivate' then null as value1 else value1 end,
case when type='deactivate' then null as value2 else value2 end,
case when type='deactivate' then null as value3 else value3 end,
case when type='deactivate' then null as value4 else value4 end,
case when type='deactivate' then null as value5 else value5 end,
case when type='deactivate' then value6 end,
case when type='deactivate' then deactivate_date end,
case when type='deactivate' then status end
from typetable
But whenever the pid changes I am getting values in value1 to 5. Is there any way in my data whenever I see type='deactivate' I have to ignore the values from value1 to 5 for all the types in the same ID? The output should be like nulls for ID- 1 & 3 mentioned below.
id pid type value1 value2 value3 value4 value5 value6 deactive date Status
0 1 case 99 null null null null null null
0 2 test null 101 null null null null null
0 3 levels null null CAAD null null null null
0 4 package null null null null DSIT null null
1 1 case null null null null null null null
1 2 test null null null null null null null
1 3 levels null null null null null null null
1 4 package null null null null null null null
1 5 deactivate null null null null null 9999999 9/1/2014 Void ID
2 1 case CLR 6# null null null null null null
2 2 test null 6 null null null null null
2 3 levels null null MAA null null null null
3 1 case null null null null null null null
3 2 test null null null null null null null
3 3 levels null null null null null null null
3 4 package null null null null null null null
3 5 deactivate null null null null null 9999999 1/7/2016 Closed