Forum Discussion
Scorpion_S1
Apr 02, 2024Copper Contributor
SQL rows to collumns
Hi everyone, I need your help. I have a view that's return the result in this format: but I need to have an output like this: Does anyone have an idea on how to do it? Thanks
- Apr 03, 2024hi,
You can use this Query
SELECT Cod,ISNULL(ABF,0) ABF,ISNULL(SCA,0) SCA,ISNULL(SCC,0) SCC, ISNULL(MTV,0) MTV,ISNULL(PCP,0) PCP,ISNULL(SDT,0) SDT
FROM <YouTableName>
PIVOT
(
MAX(value) FOR Name in([ABF],[SCA],[SCC],[MTV],[PCP],[SDT])
)
as PivotTable
hope it'll work
Thanks
olafhelper
Apr 03, 2024Bronze Contributor
Scorpion_S1 , see adtitional Using PIVOT and UNPIVOT - SQL Server | Microsoft Learn