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 |
|
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2011-08-05 : 16:31:04
|
| I'd like to convert this table:DateKey CustID CustName Amount20100701 123454 Cust ABC 0.0020100703 327645 Cust XYZ 0.0020100705 466506 Cust BBB 0.0020100710 217728 Cust MMM 0.0020100711 884013 Cust WWW 0.0020100720 300182 Cust PBR 4127.0020100805 659914 Cust FBI 1763.0020100812 333856 Cust CIA 821.0020110702 123457 Cust ABC 1439.0020110707 327648 Cust XYZ 1152.0020110708 466508 Cust BBB 985.0020110724 217725 Cust MMM 23671.0020110726 884013 Cust WWW 33406.0020110801 300182 Cust PBR 0.0020110805 659912 Cust FBI 1689.0020110810 333852 Cust CIA 941.00Into a table with the following columns with the above data:CustName CustID AmountsBetween20100701and20110630 AmountsBetween20110701and20120630 TotalAny advice appreciated, thanks!! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-05 : 20:04:00
|
[code]select CustName, CustID, AmountsBetween20100701and20110630 = sum(case when DateKey between '20100701' and '20110630' then Amount end), AmountsBetween20110701and20120630 = sum(case when DateKey between '20110701' and '20120630' then Amount end), total = sum(Amount)from yourtablegroup by CustName, CustID[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|