Friday, April 24, 2020

PIVOT EXAMPLE1 T-SQL

Problem





 Output



Solution


select code,
max(case when number=1 then pack end) pack1,
max(case when number=1 then uom end) uom1,
max(case when number=2 then pack end) pack2,
max(case when number=2 then uom end) uom2,
max(case when number=3 then pack end) pack3,
max(case when number=3 then uom end) uom3,
max(case when number=4 then pack end) pack4,
max(case when number=4 then uom end) uom4,
max(case when number=5 then pack end) pack5,
max(case when number=5 then uom end) uom5
from
(
SELECT  CODE,pack,uom ,row_number() over(partition by code order by pack) as number FROM [dbo].[UNPIVOT]
) a
group by code



No comments:

Post a Comment

Sort by Month and year in the table

  Solved: Sort by month in Power BI - Microsoft Power BI Community