森栏
即使SQLMenace的答案已被接受,SET您也应该注意一个重要的选择设置日期如果一周的第一天已更改,则DATENAME将返回正确的日期名称,但返回的DATEPART值将不同,如下所示。declare @DefaultDateFirst intset @DefaultDateFirst = @@datefirst--; 7 First day of week is "Sunday" by defaultselect [@DefaultDateFirst] = @DefaultDateFirst set datefirst @DefaultDateFirstselect datename(dw,getdate()) -- Saturdayselect datepart(dw,getdate()) -- 7--; Set the first day of week to * TUESDAY * --; (some people start their week on Tuesdays...)set datefirst 2select datename(dw,getdate()) -- Saturday--; Returns 5 because Saturday is the 5th day since Tuesday.--; Tue 1, Wed 2, Th 3, Fri 4, Sat 5select datepart(dw,getdate()) -- 5 <-- It's not 7!set datefirst @DefaultDateFirst