Reputation: 20292
I have a table with 2 columns:]
ID Name
1 A
1 B
1 C
1 D
2 E
2 F
And I want write a query to have output like :
1 A B C D
2 E F
It's possible ?
Upvotes: 0
Views: 58
Reputation: 125644
a good article you can look at :
http://www.simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/
Upvotes: 1
Reputation: 9265
You want a Pivot, which is easy in excel, but requires (I believe) quite a bit of work in SQL Server, as it is hard to determine how many columns you need. You could dynamically construct the sql based on a max() aggregate, I suppose.
Start looking here
Upvotes: 2