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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-02-26 : 09:15:39
|
| Keith writes "Here is a sql statement that works but I need one additional thing that I can't figure out how to do. select paymentname as name,sum(CASEWHEN paymentname = 'cash' THEN amountELSE amount + tipEND) as idealamountFROM paymentsGROUP BY paymentnameI need to produce a record set of payments plus tips for the payment type except for cash payments where I need the payment minus all tips for all payments types. This sql statements does it except the cash part.Any help would be much appreciated." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-02-26 : 09:30:41
|
| Thios seems t obe what you are asking for but I doubt if it's what you want.select paymentname as name,sum(CASEWHEN paymentname = 'cash' THEN amount ELSE amount + tipEND) - max(case when paymentname = 'cash' then tips.tipsum else 0 end)FROM payments, (select tipsum = sum(tips) from payments) as tipsGROUP BY paymentname==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|