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
 General SQL Server Forums
 New to SQL Server Programming
 Select statement with totals

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2010-06-02 : 12:57:27

I need to modify the following code so that if the original order type is = 'C' then it needs to multiply tot_sls_amt by -1 if orig_ord_type is anything else then just tot_sls_amt.

My final result would show total sales grouped by year so that the credits are subtracted from the amount.


SELECT TOP 100 PERCENT cus_no, SUM(tot_sls_amt) AS Expr1, LEFT(inv_dt, 4) AS [year]
FROM dbo.OEHDRHST_SQL
WHERE (orig_ord_type <> 'C')
GROUP BY LEFT(inv_dt, 4), cus_no
ORDER BY cus_no

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-06-02 : 13:19:19
SUM(CASE WHEN orig_ord_type ='C' THEN tot_sls_amt*-1 ELSE tot_sls_amt END)

jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -