Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mitin
Yak Posting Veteran
81 Posts |
Posted - 2013-03-06 : 12:16:22
|
Hi, I have data that is loaded into a table automatically, in this table it is in the following format:Server Metric TS Valuea 1 1pm 50a 2 1pm 0a 3 1pm 9a 4 1pm 81 I want to know how I can get the data from this table, into another table in the following format:Server M1 M2 M3 M4 TimeStampa 50 0 9 81 Really hope this is possible, how can it be acieved, anyone got a quer for this? seems like it would be difficult to me but... hopefully I will be surprised :)Thanks guys!! :) |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-06 : 12:23:50
|
[code]SELECT Server,MAX(CASE WHEN Metric=1 THEN Value END) AS M1,MAX(CASE WHEN Metric=2 THEN Value END) AS M2,MAX(CASE WHEN Metric=3 THEN Value END) AS M3,MAX(CASE WHEN Metric=4 THEN Value END) AS M4,GETDATE() AS TimestampFROM TableGROUP BY Server[/code]I hope MEtric will always have values as 1 to 4------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|