sql server - Convert columns values into multiple records -
in sql server 2008, have table following columns , data
date name colors color1 color2 color3 nov01 john red nov02 mike green blue grey nov03 melissa yellow orange nov10 rita pink red
i want make new table or change above table data shown as
date name colors nov01 john red nov02 mike green nov02 mike blue nov02 mike grey nov03 melissa yellow nov03 melissa orange nov10 rita pink nov10 rita red
thanks
or using pivot & unpivot
select t.date, unpvt.name, unpvt.color (select name, colors, color1, color2, color3 dbo.mytable) p unpivot (color [date] in (colors, color1, color2, color3) )as unpvt join dbo.mytable t on t.[name] = unpvt.[name] unpvt.color != ''
Comments
Post a Comment