We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Convert VBA into User Defined Function (SQL Server 2000)

Tom Knowlton
Tom Knowlton asked
Medium Priority
Last Modified: 2011-10-03
Please provide working source code for the following, such that I can call a User Defined Function and get the same results as the VBA functions:

VBA Function:

Function ForwardDays(intDays As Long, Optional datStartDate As Date) As Date
Dim X As Long
    If datStartDate = 0 Then
        datStartDate = Date
    End If
For X = 1 To intDays
datStartDate = NextWorkDay(datStartDate)
Next X
ForwardDays = datStartDate
End Function

Function NextWorkDay(Optional datDate As Date) As Date
    If datDate = 0 Then
        datDate = Date
    End If
    Select Case Weekday(datDate)
    Case 1 To 5
    NextWorkDay = datDate + 1
    Case 6
    NextWorkDay = datDate + 3
    Case 7
    NextWorkDay = datDate + 2
    End Select
End Function


User Defined Function equivalent:



Watch Question

Tom KnowltonWeb developer


Sample call to Forward Days:


So it is 5 business days from today  (skip the weekend)
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Tom KnowltonWeb developer


Thank you both.

This is just part of a larger conversion I am doing from Access over to SQL Server.

I may just have the DBA write it.

But this helps.

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.