SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subtraction issues
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 11/20/2012 :  08:58:43  Show Profile  Reply with Quote
Hello once again

I am having problems with my sql query

I have worked out a calculation which is correct, however from the table i am referencing from, all the figures have a - in front of them

Consequently when i am trying to a subtraction on this, my figures are incorrect ( as it sees that two - - = a positive )

Is there any way i can change this – within my case statement below ?
My query is

select
o.ParentID,
s.[FDMSAccountNo],
SUM(Case WHEN year(period) = '2011' and merch_purch_fees < 0 THEN [Merch_Purch_Fees] WHEN [Merch_Purch_Fees] > = 0 THEN ISNULL([Merch_Purch_Fees],0) + ISNULL([Per_Tran_Fees],0) END) AS [MSC2011],
FROM [FDMS].[dbo].[Fact_Omnipay_Profitability]s inner join fdms.dbo.Dim_Outlet o on o.FDMSAccountNo = s.FDMSAccountNo
where year(period) > 2010 and s.FDMSAccountNo in (select FDMSAccountNo from #Accounts)
group by s.FDMSAccountNo,o.ParentID

hoffman
Starting Member

9 Posts

Posted - 11/20/2012 :  09:10:02  Show Profile  Reply with Quote
Hi masond,

You can turn negative values into positive ones by multiplying them by -1.

Case WHEN year(period) = '2011' and merch_purch_fees < 0 THEN [Merch_Purch_Fees]*(-1) WHEN [Merch_Purch_Fees] > = 0 THEN ISNULL([Merch_Purch_Fees],0) + ISNULL([Per_Tran_Fees],0) END
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000