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 ?
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 ?
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
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/
Your question is basically identical to http://stackoverflow.com/questions/451415/simulating-group-concat-mysql-function-in-ms-sql-server-2005