Solved

Banker's Rounding in SQL Server 2000

Posted on 2004-10-18
3
856 Views
Last Modified: 2008-01-16
How do I use Banker's Rounding in SQL Server 2000.  I tried to convert the function I found (http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B196652) but was unable to make it work. Is there a built in function or a UDF someone has used in the past?

Thanks!


0
Comment
Question by:SpreadTheWord
3 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 500 total points
ID: 12343376
Mmmmm.... try this one

Create Function dbo.udf_BankerRound(@Amt as Money)
RETURNS Money
AS
BEGIN
   Declare @Result Money
   Declare @Sgn smallint

   IF @Amt = Floor(@Amt)
      Set @Result = @Amt
   ELSE
   BEGIN
      Set @Sgn = Sign(Ceiling(@Amt) - 2 * @Amt + Floor(@Amt))
      If @Sgn = 1
         Set @Result = Floor(@Amt)
      ELSE
         If @Sgn = 0
             Set @Result = 2 * Round(@amt / 2, 0)
         Else
             Set @Result = Ceiling(@Amt)
   END
Return(@Result)
END
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question