user278618
user278618

Reputation: 20292

Help with select query

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

Answers (2)

Luke Schafer
Luke Schafer

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

Related Questions