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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Reformat Data - Merge Rows?

Author  Topic 

jun0
Starting Member

32 Posts

Posted - 2013-03-13 : 11:47:51
Hi, I have data in a table as in the sample below:



PMHOST INSTANCE TIMESTAMP PMOBJECT DISKWRITE PERCFREE FREEMB SPLITIOSEC

ahermontest1 "D:" 1130308054059000 LogicalDisk NULL NULL NULL 0
ahermontest1 "D:" 1130308054059000 LogicalDisk NULL 98 NULL NULL
ahermontest1 "D:" 1130308054059000 LogicalDisk NULL NULL 40202 NULL



I want to 'merge' these rows so that they will look like this:



PMHOST INSTANCE TIMESTAMP PMOBJECT DISKWRITE PERCFREE FREEMB SPLITIOSEC

ahermontest1 "D:" 1130308054059000 LogicalDisk NULL 98 40202 0


Can anyone help on how to do this?

Thanks :)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-13 : 12:02:01
as per your posted sample data, this is enough

SELECT PMHOST,
INSTANCE,
TIMESTAMP,
PMOBJECT,
MAX(DISKWRITE),
MAX(PERCFREE),
MAX(FREEMB),
MAX(SPLITIOSEC)
FROM Table
GROUP BY PMHOST,
INSTANCE,
TIMESTAMP,
PMOBJECT


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

Go to Top of Page
   

- Advertisement -