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 giving me wrong figure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 11/07/2012 :  05:01:52  Show Profile  Reply with Quote
Hey

Guys really quick random question

i am having problems doing a subtraction and i don’t know why.

This is my query

SELECT
[FDMSAccountNo],
SUM([Tot_Purch_Amt]) as GrossSales,
SUM([Refund_Amt])as SalesRefunds,
sum([Tot_Purch_Amt])-sum([Refund_Amt]) as SaleNet,
SUM([DCC_Purch_Amt])as DCC,
SUM([DCC_Refund_Amt])as DCCRefunds,
SUM([DCC_Purch_Amt])-SUM([DCC_Refund_Amt]) as DCCnet,
SUM([Adjs]) as adjustments
FROM [FDMS].[dbo].[Fact_Omnipay_Profitability]
group by FDMSAccountNo

i want to get my grosssales column – Salesrefund to produce a netfigure

At present my query is giving me an inaccurate figure for eg
gross sales Salesrefund SaleNet
2484691.81 -32893.84 2517585.65

when in fact the salesnet should be 2451797.97

Any ideas why ?

webfred
Flowing Fount of Yak Knowledge

Germany
8768 Posts

Posted - 11/07/2012 :  05:08:35  Show Profile  Visit webfred's Homepage  Reply with Quote
Can you at least please post the data types?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 11/07/2012 :  05:19:21  Show Profile  Reply with Quote
Hi Webfred

What do you mean by data types ? string, varchar etc ?
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8768 Posts

Posted - 11/07/2012 :  05:23:21  Show Profile  Visit webfred's Homepage  Reply with Quote
Yes.
The column Tot_Purch_Amt and the other involved columns - they have a data type we need to know.


Too old to Rock'n'Roll too young to die.
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 11/07/2012 :  05:30:48  Show Profile  Reply with Quote
Hi webfred

i am unable to find that out at present :( as i dont have rights to the table. :(
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 11/07/2012 :  06:21:30  Show Profile  Reply with Quote
quote:
At present my query is giving me an inaccurate figure for eg
gross sales Salesrefund SaleNet
2484691.81 -32893.84 2517585.65

when in fact the salesnet should be 2451797.97

Do this, u will get 2451797.97

sum([Tot_Purch_Amt])+sum([Refund_Amt]) as SaleNet








--
Chandu
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 11/07/2012 :  08:03:10  Show Profile  Reply with Quote
HI bandi

I had to do this

Sum([Tot_Purch_Amt])-sum(-[Refund_Amt]) as SaleNet,

this returned the correct value
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 11/07/2012 :  08:07:36  Show Profile  Reply with Quote
quote:
Originally posted by masond

HI bandi

I had to do this

Sum([Tot_Purch_Amt])-sum(-[Refund_Amt]) as SaleNet,

this returned the correct value



okey that is also fine. Why i suggested + means i thought u had Refund_Amt with negative values...............



--
Chandu
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.09 seconds. Powered By: Snitz Forums 2000