Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have convert multiple row into single row(multiple column) in sql server.

For example,

sql data is followed by,

SQL
name     Age

Anbu     45
senthil  25
Raj      27



My required output is

SQL
Anbu  45  Senthil  25  Raj 27



How to do this?
Posted
Updated 16-Dec-15 22:34pm
v2
Comments
deepankarbhatnagar 17-Dec-15 5:59am    
Not getting, please explain.

If 1000 rows were there then, how could it be possible. With the help of 'Pivot' you can only convert rows into column but your requirement is ambiguous.
ZurdoDev 17-Dec-15 8:15am    
You can look into Pivoting in SQL.

1 solution

I not infrequently need to convert column data into row data - typically when data is stored in tagged fashion. This is accomplished by inner-joins on the same table, but with different alias' and constraints on each one.

SQL
SELECT A.name, A,age, B.name, B.age, C.name, C.age
 FROM YOUR_TABLE as A
  INNER JOIN YOUR_TABLE as B
    ON A.something=b.something 
  INNER JOIN YOUR_TABLE C
    ON B.something=c.something 
 WHERE A.whatever=value 
 AND B.whatever=value 
 AND C.whatever=value

etc. etc. etc.

You'll need to determine how to link these.
 
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