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)
 Need Help on merging records
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

julius.delorino
Starting Member

Philippines
29 Posts

Posted - 06/13/2012 :  23:00:02  Show Profile  Reply with Quote
Good Day, i am having a problem on merging records into a single row per client.

SAMPLE TABLE:
ClientCode |ClientsName January ADB February ADB March ADB April ADB
A00001 PAWINGI SR,ALBERT,DUMANGENG NULL 0 NULL 0 3/26/2012 111208.15 NULL 0
A00001 PAWINGI SR,ALBERT,DUMANGENG NULL 0 NULL 0 NULL 0 4/26/2012 100208.15
A00003 DULNUAN,LUZVIMINDA,G NULL 0 NULL 0 3/26/2012 2000 NULL 0
A00003 DULNUAN,LUZVIMINDA,G NULL 0 NULL 0 NULL 0 4/26/2012 6343.8


OUTPUT TABLE:
ClientCode |ClientsName January ADB February ADB March ADB April ADB
A00001 PAWINGI SR,ALBERT,DUMANGENG NULL 0 NULL 0 3/26/2012 111208.15 4/26/2012 100208.15
A00003 DULNUAN,LUZVIMINDA,G NULL 0 NULL 0 3/26/2012 2000 4/26/2012 6343.8



Thank you so much for your help,more power SQLTEAM!

khtan
In (Som, Ni, Yak)

Singapore
16745 Posts

Posted - 06/13/2012 :  23:02:51  Show Profile  Reply with Quote

SELECT ClientCode, ClientsName, 
       [January ADB]  = sum([January ADB]), 
       [February ADB] = sum([February ADB]), 
       [March ADB]    = sum([March ADB]),
       [April ADB]    = sum([April ADB])
FROM   yourtable
GROUP BY ClientCode, ClientsName



KH
Time is always against us

Go to Top of Page

julius.delorino
Starting Member

Philippines
29 Posts

Posted - 06/13/2012 :  23:08:47  Show Profile  Reply with Quote
Thanks for your reply sir,but im thinking of using PIVOT to attain desired result.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16745 Posts

Posted - 06/13/2012 :  23:12:40  Show Profile  Reply with Quote
The structure of your data is not suitable for PIVOT. For what you required, a simple SUM() with GROUP BY will do.


KH
Time is always against us

Go to Top of Page

julius.delorino
Starting Member

Philippines
29 Posts

Posted - 06/13/2012 :  23:23:43  Show Profile  Reply with Quote
well consider your solution,thank you so much sir for your help.
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.22 seconds. Powered By: Snitz Forums 2000