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.
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 ADBA00001 PAWINGI SR,ALBERT,DUMANGENG NULL 0 NULL 0 3/26/2012 111208.15 NULL 0A00001 PAWINGI SR,ALBERT,DUMANGENG NULL 0 NULL 0 NULL 0 4/26/2012 100208.15A00003 DULNUAN,LUZVIMINDA,G NULL 0 NULL 0 3/26/2012 2000 NULL 0A00003 DULNUAN,LUZVIMINDA,G NULL 0 NULL 0 NULL 0 4/26/2012 6343.8OUTPUT TABLE:ClientCode |ClientsName January ADB February ADB March ADB April ADBA00001 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 yourtableGROUP BY ClientCode, ClientsName[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
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. |
 |
|
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] |
 |
|
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. |
 |
|
|
|
|
|
|