Pivot question

Hi ,

Could you help me in getting the below results,

For ex i have data like

ID Pink Blue Red Green
1 1 0 1 0
2 0 0 1 1
3 1 1 0 0
4 0 0 1 0
5 1 1 1 0

Expected output:
ID Color
1 Pink
1 Red
2 Red
2 Yellow
3 Pink
3 Black
4 Red
5 Pink
5 Black
5 Red

Welcome to forum.
Please always provide read usable data with your question

create table #shaka(ID int, Pink int, Blue int, Red int,  Green int)

insert into #shaka
select 1, 1, 0, 1, 0 union
select 2, 0, 0, 1, 1 union
select 3, 1, 1, 0, 0  union
select 4, 0, 0, 1, 0  union
select 5, 1, 1, 1, 0

select * From #shaka


SELECT Colors,Name
  FROM #shaka t  
UNPIVOT  
(  
	Colors 
	FOR Name IN (Pink, Blue, Red, Green)  
) AS unpvt 


drop table #shaka
1 Like

Thank you very much