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
 Having clause and my 0.01s!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jodders
Starting Member

United Kingdom
41 Posts

Posted - 09/19/2013 :  06:48:51  Show Profile  Reply with Quote
Morning,

I am trying to eliminate a rounding issue with my query. It's bring back -0.01 and +0.01 which I don't want it to. I have played around with my having clause but have hit a road block.



select....

sum(case when acct_type <> 'IN' then sign*(amount*rate) else 0 end) 'A',
sum(case when acct_type = 'IN' then sign*(amount*rate) else 0 end) 'D'

join.....
where...
group by...
having sum(sign*amount) <> 0 


Any help?

Thanks
Jod

SwePeso
Patron Saint of Lost Yaks

Sweden
30282 Posts

Posted - 09/19/2013 :  07:07:25  Show Profile  Visit SwePeso's Homepage  Reply with Quote
CAST( sign * amount * rate AS INT)


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

jodders
Starting Member

United Kingdom
41 Posts

Posted - 09/19/2013 :  07:37:23  Show Profile  Reply with Quote
Thanks SwePeso, do i need to add that into the having clause?
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3760 Posts

Posted - 09/19/2013 :  09:22:39  Show Profile  Reply with Quote
Add to both - in the select clause and in the having clause. You have to decide whether you want to round each individual rows separately, or round only the aggregate. If I had to guess, I would say use the rounding on the aggregate.
select....

CAST(sum(case when acct_type <> 'IN' then sign*(amount*rate) else 0 end) AS INT) 'A',
CAST(sum(case when acct_type = 'IN' then sign*(amount*rate) else 0 end) AS INT) 'D'

join.....
where...
group by...
having CAST(sum(sign*amount) AS INT) <> 0
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.05 seconds. Powered By: Snitz Forums 2000