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 - Merge Rows?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jun0
Starting Member

United Kingdom
32 Posts

Posted - 03/13/2013 :  11:47:51  Show Profile  Reply with Quote
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 :)

Edited by - jun0 on 03/13/2013 11:48:48

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 03/13/2013 :  12:02:01  Show Profile  Reply with Quote
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
  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.04 seconds. Powered By: Snitz Forums 2000