Slight change to my original submission. If the interval is less than a week and the day of week is not found in that interval the following adjustments will need to be made. (Obviously if the interval is less than a week you can count by hand how many specific days of the week are in the interval but I don't want to be sloppy with code.)
1) You will need to initialize the variable @num to zero.
2) Change the predicate in the first WHILE statement to:
WHILE @found = 0 AND (@StartDate <= @EndDate)
3) Change the final statement to the following:
IF @StartDate <= @EndDate
SET @num = (DATEDIFF(day,@StartDate, @EndDate) / 7) + 1
That should take care of the situation.