> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Trust But Verify
- URL: https://nolongerset.com/trust-but-verify/
- Published: 2021-09-05T03:15:31.000Z
- Updated: 2026-05-08T13:02:35.000Z
- Description: What Ronald Reagan's Words Can Teach Us About the Sample Code We Find on the Internet
- Author: Mike Wolfe
- Tags: SQL Server, Testing, #Import 2026-05-20 02:59

[Yesterday](https://nolongerset.com/vba-to-tsql-via-tdd/), I wrote about the ten steps you can follow to convert a VBA function to a SQL Server scalar function. 

Those ten steps can be reduced to three words: **test-driven development**. The steps are nothing more than applying TDD principles to the specific problem of converting a VBA function to SQL Server. That said, they are difficult to explain–and even harder to comprehend–without a practical example.

**Let's convert the VBA.Round function to a SQL Server scalar function**.

## Why VBA.Round?

VBA and SQL Server both have built-in Round functions, but they produce different results.

The [VBA Round function](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function) uses [banker's rounding](https://nolongerset.com/a-rounding-we-will-go/). The [SQL Server Round function](https://docs.microsoft.com/en-us/sql/t-sql/functions/round-transact-sql?view=sql-server-ver15) does not. This means that `Round(2.5, 0)` will return 2 in VBA but 3 in SQL Server. This is a problem if you want to migrate business logic that relies on rounded numbers from VBA to SQL Server.

To achieve success, we need to create 100% functional equivalence between the VBA Round function and our custom SQL Server scalar function.

## Programming Advice from Ronald Reagan

> "[Trust, but verify](https://en.wikipedia.org/wiki/Trust,%5Fbut%5Fverify)."

There are [several pages on the web](https://www.google.com/search?q=bankers%20rounding%20in%20SQL%20Server) with solutions for implementing bankers rounding in SQL Server. Any one of them might be perfect. But there's a good chance many of them are merely *very good*. In my situation, very good was not going to cut it. I needed my SQL Server banker's rounding function to produce output *identical* to output from the VBA.Round function.

It's one thing to **trust** third-party code from a reputable site like [StackOverflow](https://stackoverflow.com/q/18847374/154439), but before putting it into production you should always **verify** it does what you expect.

And to do *that*, we will follow the ten steps from [yesterday's article](https://nolongerset.com/vba-to-tsql-via-tdd/).

### Referenced articles

[How to Convert a VBA Function to a SQL Server Scalar FunctionMS Access Developers Can Remove All the Risk From This Complex Process With These 3 Words![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/09/caterpillars-2869783_1920.jpg)](https://nolongerset.com/vba-to-tsql-via-tdd/)

### External references

[Round function (Visual Basic for Applications)Microsoft Docso365devx](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function)

[Trust, but verify - Wikipedia![](https://en.wikipedia.org/static/apple-touch/wikipedia.png)Wikimedia Foundation, Inc.Contributors to Wikimedia projects![](https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/President_Ronald_Reagan_and_Mikhail_Gorbachev_during_the_second_plenary_session.jpg/170px-President_Ronald_Reagan_and_Mikhail_Gorbachev_during_the_second_plenary_session.jpg)](https://en.wikipedia.org/wiki/Trust,%5Fbut%5Fverify)

[bankers rounding in SQL Server - Google SearchGoogle Search![](https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png)](https://www.google.com/search?q=bankers%20rounding%20in%20SQL%20Server)

[SQL Server Rounding Issue where there is 5As far as i know according to mathematics rounding should work as below when rounding number is 5\. 2.435 =&gt; 2.44 (Round Up, if rounding to digit(3) is odd number)2.445 =&gt; 2.44 (Round Down, if![](https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a)Stack OverflowWijitha![](https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=73d79a89bded)](https://stackoverflow.com/q/18847374/154439)

*Image by [WikiImages](https://pixabay.com/users/wikiimages-1897/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=67550) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=67550)*