Possible Duplicate:
T-SQL Group Rows Into Columns
I have a table _data that is formatted like this
TimeStamp MeterID Value
2012-04-15 13:00:00.000 CK1992 152.64
2012-04-15 12:45:00.000 CK1992 151.695
2012-07-06 12:45:00.000 CK1992 150.84
2012-09-04 12:00:00.000 CK1992 150.66
2012-04-15 12:15:00.000 CK1992 150.57
I need to be able to format that table as something like this
Timestamp MeterID1 MeterID2 MeterID3
stamphere value value value
I have a lot of different MeterIDs so it needs extract it accordingly.
Here is my existing select statement:
SELECT [TimeStamp]
,[MeterID]
,[Value]
FROM [dbo].[_Data]
How can I make this work? Thanks for your help!
You might check the information in SQL Server dynamic PIVOT query? since you don’t know how many columns you will have.
Also, you can potentially use
PIVOTas it was introduced in SQL Server 2005: