Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Table1

column1 column2 column3 column4 column5

  abc     100     200      300    400

  xyz     025     020      035    010

  Mnop    001     002      003    004



How to convert all column into rows please give some examples

[edit]Code block added - OriginalGriff[/edit]

What I have tried:

i am not clear in UNPIVOT concept
Posted
Updated 7-Jun-16 11:49am
v6
Comments
OriginalGriff 7-Jun-16 2:49am    
Exactly what do you expect to get as a result?
What have you tried?
OriginalGriff 7-Jun-16 3:28am    
Stop bumping this. It won't get you an answer any faster - in fact it may be slower, because it's rude, and we don't like rude people here.
Add information by all means - you have been asked for some - but just editing it to move it to the top of the queue? That's just rude.
murkalkiran 7-Jun-16 3:41am    
Sorry brother i was not clear in what i want , but now i am clear and working on it ,if any issue definitely i will post it with clear information
thanku sorry for the unclear question

1 solution

Your question is unclear, but my best guess is:

SQL
DECLARE @tmp TABLE (column1 VARCHAR(30), column2 VARCHAR(30),
			column3 VARCHAR(30), column4 VARCHAR(30), column5 VARCHAR(30))

INSERT INTO @tmp (column1, column2, column3, column4, column5)
VALUES('abc', '100', '200', '300', '400'),
('xyz', '025', '020', '035 ', '010'),
('Mnop', '001', '002', '003', '004')

SELECT column1 As [Header], [Description], [Value] 
FROM @tmp
UNPIVOT ([Value] FOR [Description] IN (column2, column3, column4, column5)) AS unpvt



Result:
Header	Description Value
abc	    column2	    100
abc	    column3	    200
abc	    column4	    300
abc	    column5	    400
xyz	    column2	    025
xyz	    column3	    020
xyz	    column4	    035 
xyz	    column5	    010
Mnop	column2	    001
Mnop	column3	    002
Mnop	column4	    003
Mnop	column5	    004


For further information, please see: Using PIVOT and UNPIVOT[^]
 
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