I need to convert SQL table into expected o/p.
Current table
id status month
100 P August
101 D August
101 P August
102 P August
102 P sept
expected o/p:
id August Sept
100 P NULL
101 D NULL
101 P NULL
102 P P
I need all records.
Use Pivot.
select * FROM (
SELECT id , status, month,
ROW_NUMBER() over( partition by id,month order by id,status )rnk
FROM #tableName w
) up
PIVOT ( max(status) FOR month IN ([August],[Sept])) AS pvt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With