0

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 ?

user278618
  • 19,306
  • 42
  • 126
  • 196
  • possible duplicate of [Simulating group\_concat MySQL function in Microsoft SQL Server 2005?](http://stackoverflow.com/questions/451415/simulating-group-concat-mysql-function-in-microsoft-sql-server-2005) – zwol May 09 '14 at 20:39

2 Answers2

2

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

Luke Schafer
  • 9,209
  • 2
  • 28
  • 29
1

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/

Haim Evgi
  • 123,187
  • 45
  • 217
  • 223