Solved

Banker's Rounding in SQL Server 2000

Posted on 2004-10-18
3
846 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 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