> ## 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.

# VBA to T-SQL via TDD: Step 9
- URL: https://nolongerset.com/vba-to-tsql-via-tdd-step-9/
- Published: 2021-09-17T02:12:33.000Z
- Updated: 2026-05-08T13:02:22.000Z
- Description: Step 9. Execute the test query in SQL Server
- Author: Mike Wolfe
- Tags: VBA to T-SQL via TDD, #Import 2026-05-20 02:59

*This is Part 1 of [my series](https://nolongerset.com/vba-to-tsql-via-tdd/) on converting a VBA function to a SQL Server scalar function using test driven development. As a proof of concept, I will be [re-implementing the VBA Round function](https://nolongerset.com/trust-but-verify/) (which uses bankers rounding) as a SQL Server scalar function.*

---

## Testing Against the Dummy Function

In [Step 7](https://nolongerset.com/vba-to-tsql-via-tdd-step-7/), we ran our [test query](https://nolongerset.com/vba-to-tsql-via-tdd-step-6/) to verify that all the tests fail when running against a [dummy function](https://nolongerset.com/vba-to-tsql-via-tdd-step-5/) that is hard-coded to always return zero. As a reminder, here was the dummy function:

```sql
CREATE FUNCTION dbo.VBA_Round(
    @OriginalVal sql_variant,
    @RoundDigits int
)
RETURNS float
AS
BEGIN
    RETURN 0
END;
```

The test query returned 17 rows, which means that 17 out of 19 test cases failed:

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/09/image-52.png)

## Testing the Refactored Function

In [Step 8](https://nolongerset.com/vba-to-tsql-via-tdd-step-8/), we refactored the *VBA\_Round()* function to address these 17 failures. Here's the ALTER FUNCTION statement we ran:

```sql
ALTER FUNCTION [dbo].[VBA_Round](
    @OriginalVal sql_variant,
    @RoundDigits int
)
RETURNS float
AS
BEGIN
    RETURN Round(Cast(@OriginalVal as float), @RoundDigits)
END;
```

After executing the above statement, it is time to re-run the test query. 

The test query now returns only four records (down from 17). In other words, the results below represent the only tests from our test suite that are still failing. Once we get these remaining tests to pass, we are home free.

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/09/image-53.png)

### 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/)

[Trust But VerifyWhat Ronald Reagan’s Words Can Teach Us About the Sample Code We Find on the Internet![](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/president-67550_1920.jpg)](https://nolongerset.com/trust-but-verify/)

[VBA to T-SQL via TDD: Step 7Step 7\. Execute the test query in SQL Server to verify it fails![](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/Step7.png)](https://nolongerset.com/vba-to-tsql-via-tdd-step-7/)

[VBA to T-SQL via TDD: Step 6Step 6\. Build a test query in SQL Server to return failing tests![](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/Step6.png)](https://nolongerset.com/vba-to-tsql-via-tdd-step-6/)

[VBA to T-SQL via TDD: Step 5Step 5\. Create a dummy scalar function in SQL Server![](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/Step5.png)](https://nolongerset.com/vba-to-tsql-via-tdd-step-5/)

[VBA to T-SQL via TDD: Step 8Step 8\. Alter the scalar function to address failures![](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/Step8.png)](https://nolongerset.com/vba-to-tsql-via-tdd-step-8/)