• Trying to explain the logic, I found there was a mistake when the first day of a month is Sunday. If you grab a calendar, it becomes evident. From Tuesday to Saturday, you'll end up having a weekend before the fifth day, so you need to look for the 7th day. On Sunday, you only have one day from your weekend and the whole week to get to the fifth business day, so you'll look for the 6th. On Monday, you get no weekends before the 5th business day, so you just use the 5th.

    DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) , 0) will give you the first day of the month (the +n in the example is to go through different months). You just need to add the necessary days to get to the 5th, 6th or 7th depending on the day of week of the first.

    Here's the updated example:

    SELECT CASE DATENAME(DW, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0))

    WHEN 'Monday' THEN DATEADD( DD, 4, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0))

    WHEN 'Sunday' THEN DATEADD( DD, 5, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0))

    ELSE DATEADD( DD, 6, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0)) END

    ,DATENAME(DW, CASE DATENAME(DW, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0))

    WHEN 'Monday' THEN DATEADD( DD, 4, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0))

    WHEN 'Sunday' THEN DATEADD( DD, 5, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0))

    ELSE DATEADD( DD, 6, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0)) END) AS [5thDay]

    ,DATENAME(DW, DATEADD( MM, DATEDIFF(MM, 0, GETDATE()) + n, 0)) AS [1stDay]

    FROM (VALUES(0), (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14))e(n)

    ORDER BY [1stDay]

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2