tags:

views:

40

answers:

3

Hi

Suppose i have the following data in a table:

ID  Type    Preis
1   1   10
1   2   20
1   3   30

and now i want it reorganized like this:

ID  Preis_A Preis_B Preis_C
1   10  20  30

How can i do this in t-sql?

A: 

Which version of SQL Server are you using? Search here for Cross-Tab and/or Pivot.

Frank Kalis
A: 

I'm using MSSQL 2008.

So far i've understand all the proposed solution and i think pivot is nice. However i might add that i sometimes i need to group types e.g. Preis_A = Type 1 and 10.

And regarding performance is pivot faster than using subqueries as proposed by Daniel Vasallo?

Sys
you should edit your question to include addition info, and not create an "answer" containing it. by adding an "answer" that contains additional question info, some people may not see this and you'll not get good answers.
KM
you can use a CTE or derived table to group Type 1 and 10 together before sending the data into a pivot
KM