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)
 Need Help on merging records

Author  Topic 

julius.delorino
Starting Member

29 Posts

Posted - 2012-06-13 : 23:00:02
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)

17689 Posts

Posted - 2012-06-13 : 23:02:51
[code]
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
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

julius.delorino
Starting Member

29 Posts

Posted - 2012-06-13 : 23:08:47
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)

17689 Posts

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


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

julius.delorino
Starting Member

29 Posts

Posted - 2012-06-13 : 23:23:43
well consider your solution,thank you so much sir for your help.
Go to Top of Page
   

- Advertisement -