SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Reformat Data?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mitin
Yak Posting Veteran

81 Posts

Posted - 03/06/2013 :  12:16:22  Show Profile  Reply with Quote
Hi, I have data that is loaded into a table automatically, in this table it is in the following format:



Server	Metric	TS	Value
a	1	1pm	50
a	2	1pm	0
a	3	1pm	9
a	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	TimeStamp
a	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

India
52323 Posts

Posted - 03/06/2013 :  12:23:50  Show Profile  Reply with Quote

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 Timestamp
FROM Table
GROUP BY Server


I hope MEtric will always have values as 1 to 4

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000