• I think something like this is what you're looking for. I didn't do extensive testing as I wrote it at work. I hope it helps.

    CREATE FUNCTION [dbo].[WeekdaysInInterval]

    ( @StartDate SMALLDATETIME, @EndDate SMALLDATETIME, @day_of_week VARCHAR(9) )

    RETURNS INT

    AS

    BEGIN

    DECLARE @found BIT, @num INT

    SET @found = 0

    --find first occurence of day of week in interval

    WHILE @found = 0 AND (@StartDate < @EndDate)

    BEGIN

    IF DATENAME(weekday,@StartDate) = @day_of_week

    BEGIN SET @found = 1 END

    ELSE

    SET @StartDate = DATEADD(day,1,@StartDate)

    END

    --find number of weeks with this day of week included

    SET @num = (DATEDIFF(day,@StartDate, @EndDate) / 7) + 1

    RETURN @num

    END