SELECT (DAY(@dt) + (((8 - (1 + ((7 - (DATEPART(dw, DATEADD (month, DATEDIFF (month, 0, @dt), 0))-1)) % 7)) -- First Sunday ))%7) -1)/7 + 1