SET DATEFIRST 1; --设置周一为每周第一天
SELECT @@DATEFIRST;WITH w AS(SELECTCONVERT(varchar(10),T.[Date],120) AS [Date],DATENAME(weekday, T.[Date] ) AS [Week],DATEPART(WK, T.[Date]) AS WeekIndexFROM(SELECTDATEADD(DAY, number, DATEADD(wk, DATEDIFF(wk, 0, getdate()), 0) ) [Date]FROMmaster..spt_valuesWHERETYPE = 'P'AND DATEADD(DAY, number, DATEADD(wk, DATEDIFF(wk, 0, getdate()), 0) ) < DATEADD(wk, DATEDIFF(wk, 0, DATEADD(dd, -1, getdate()) ), 7)) T
)
SELECTw.*
FROMw