Regardless of the actual DATEFIRST setting, the last Sunday could be found like this:
SELECT DATEADD(day,
-1 - (DATEPART(weekday, GETDATE()) + @@DATEFIRST - 2) % 7,
GETDATE()
) AS LastSunday
Replace GETDATE()
with a parameter @date
to get the last Sunday before a particular date.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…