Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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?
 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
52326 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  
 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.11 seconds. Powered By: Snitz Forums 2000