tsql - SQL SERVER PIVOT WITHOUT AGGREGATION -


I have a query whose result set looks like the table below. In the name column "C1, C2, C3" set which is well known

  id | Name | Price ------------------------------- 1C1 1C1 1 C2 | 1 c2 1 C3 | 1C3 2 C1 | 2C1 2 | C2 | 2 c 2 2c3 2C3  

I need to move it to the following

  Id. C1 | C2 | C3 ------------------------------- 1. 1C1 | 1C2 1C3 2 2c2 2c2 2C3  

Tried to achieve this with Pivits, but they do not like playing string values ​​(ie) good for non-set. There is a sign about how I can go about this?

This code is taken much more than the sample SQL Server documentation; This subquery is not really necessary here, but it has been written in the sample.

  SELECT * FROM (SELECT Id, by name, value to your_table_or_query) P PIO0 (for maximum value) Name IN (C1, C2, C3)) Private as ID order;  

Output:

  ID C1 C 2 C3 1 1C1 1C2 1C2 2C1 C2 2C3 < / Code> 

Comments