Click here to Skip to main content
14,698,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I have a datatable like bellow.
Screenshot-2 — ImgBB[^]

I want to convert into like bellow.
Screenshot-3 — ImgBB[^]

I don't have idea how can i achieve this. Any help would be highly appreciated.
Thanks in advance.

What I have tried:

I googled but unfortunately did't found any help.
Posted
Updated 2-Mar-20 0:48am

1 solution

You have to use PIVOT[^].

SELECT LabelText, [judge1], [judge2], [judge3]...
FROM 
(
    SELECT *, CONCAT('judge', CONVERT(VARCHAR(50), ROW_NUMBER() OVER(PARTITION BY qst_id ORDER BY judge_id)) AS judgeNo
    FROM YoutTable
) dt
PIVOT(SUM(Score) FOR judgeNo IN ([judge1], [judge2], [judge3]...)) pvt


Related topic: ROW_NUMBER (Transact-SQL) - SQL Server | Microsoft Docs[^]
   
v2
Comments
phil.o 2-Mar-20 6:11am
   
5'd :)
Maciej Los 2-Mar-20 8:24am
   
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900