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 |
|
masteripper
Starting Member
25 Posts |
Posted - 2008-12-05 : 02:21:01
|
| Hello to everybodyI am wondering if this can happenI have this query that with the help of CASE produces 2 columns like this(CASE WHEN (s.WareHouseAA='9') then s.Balance else 0 END) as RawBalance,(CASE WHEN (s.WareHouseAA='11') then s.Balance else 0 END) as ProductionBalance Is it possible to have the effect of Sum like Totals in AccessI have a table data like thisProduct WarehouseAA Balanceproduct1 9 9product1 11 14product2 9 3product2 11 12.1Right now i haveProducts Rawbalance ProductionBalanceproduct1 9 0product1 0 14product2 3 0product2 0 12.1And i want to have something like thisProducts Rawbalance ProductionBalanceproduct1 9 14product2 3 12.1If it has being asked before please don't judge me so hard ... i searched but probably didn't used the corrrent terminology |
|
|
chrianth
Yak Posting Veteran
50 Posts |
Posted - 2008-12-05 : 02:40:58
|
| try this..select Product, sum(RawBalance) sumRawBalance, sum(ProductionBalance) ProductionBalancefrom yourTablegroup by Producthope this helps. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-05 : 02:48:18
|
| [code]SELECT Products,SUM(CASE WHEN (s.WareHouseAA='9') then s.Balance else 0 END) as RawBalance,SUM(CASE WHEN (s.WareHouseAA='11') then s.Balance else 0 END) as ProductionBalanceFROM TableGROUP BY Products[/code] |
 |
|
|
masteripper
Starting Member
25 Posts |
Posted - 2008-12-05 : 04:57:12
|
| Well what can i say ur the best.The Funny thing is that i tried that but i forgot that in group by i have to use Having (my query is a little more complex) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-05 : 12:10:06
|
| thanks |
 |
|
|
|
|
|