Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below is my source table

RANGE	VALUE1	VALUE2	VALUE3	VALUE4	VALUE5
 R1	      1	     10	     20	     30	      50
 R2	      2	     11	     21	     31	      51
 R3	      3	     12	     22	     32	      52
 R4	      4	     13	     23	     33	      53
 R5	      5	     14	     24	     34	      54


Below is my expected result

VALUES	R1	R2	R3	R4	R5
VALUE1	1	2	3	4	5
VALUE2	10	11	12	13	14
VALUE3	20	21	22	23	24
VALUE4	30	31	32	33	34
VALUE5	50	51	52	53	54


What I have tried:

I tried using unpivot but not working as expected.
Posted
Updated 23-Jul-20 18:38pm
Comments
Richard Deeming 24-Jul-20 6:49am    
"I tried using unpivot but not working as expected."

That tells us precisely nothing. Click the green "Improve question" link and update your question to include the actual code you tried, the results of that code, and an explanation of what's wrong with the output.

1 solution

Sounds like you need a SQL PIVOT.

Read about SQL PIVOT:
MSDN: Using PIVOT and UNPIVOT[^]
Understanding PIVOT and UNPIVOT[^]
Pivoting data in SQL Server[^]

Try out!
 
Share this answer
 

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