pivot | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

pivot

Hi,
I would like to write a sql query in sql server 2005 to derive a table called tblResult from tblData as follows:
I think I should use unpivot.
tblData
Notice the dates are fields
surname 26 Dec 27 Dec 28 Dec 02 Jan 04 Jan 05 Jan
Brown 100.2 12.65 43.76 3.54 98.12 56.76
Jackson 32.21 98.34 45.54 2.65 65.11 78.86
Peterson 32.23 65.34 88.22 8.34 12.22 87.55 This is what I would like to end up with
tblResult
Surname Date price1 Price2
Brown 26 Dec 100.2 100.2
Jackson 26 Dec 32.21 32.21
Peterson 26 Dec 32.23 32.23
Brown 27 Dec 12.65 12.65
Jackson 27 Dec 98.34 98.34
Peterson 27 Dec 65.34 65.34
Brown 28 Dec 43.76 43.76
Jackson 28 Dec 45.54 45.54
Peterson 28 Dec 88.22 88.22
.
.
.
Thanks

Have you referred to the updated Books online for PIVOT topic?

]]>

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |