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
 How can I use RoundDown in SQL Server

Author  Topic 

marcoviy
Starting Member

6 Posts

Posted - 2011-05-02 : 19:54:57
Hello all,

I have the following table:

NAME VALUE
METER 1 2850.398
METER 2 2576.066

I need a stored procedure which returns the sum of the values, but first ROUNDDOWNing the reading of EVERY meter (as done in Excel), But first the rounddown must be done (not AFTER the sum) because I will get a wrong result as explained below:

1. If I first add the values and then apply the RoundDown, the result will be (which is WRONG)

TOTAL 5426.464 RoundDown -> 5426.46

2. If I first apply the RoundDown and afterwards I add the values, the result will be (which is what I NEED TO)

NAME VALUE RoundDown()
METER 1 2850.398 2850.39
METER 2 2576.066 2576.06

TOTAL 5426.45

Could you please help me with this problem? I've been looking for the RoundDown in SQL Server 2008, but I cannot find it

Thank you very much,

Marco

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-02 : 20:01:24
use round() with truncate

http://msdn.microsoft.com/en-us/library/ms175003.aspx


SELECT sum( round (VALUE, 2, 1) )
FROM . . .




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

marcoviy
Starting Member

6 Posts

Posted - 2011-05-03 : 11:15:48
Thanks khtan. That worked very well,
Marco
Go to Top of Page
   

- Advertisement -