再帰的な CTE を使用できます:
;WITH CTE AS ( SELECT convert(date,GETDATE()) sDate, DATENAME(DW, GETDATE()) sDayofWeek UNION ALL SELECT DATEADD(DAY,-1,sDate), DATENAME(DW, DATEADD(DAY,-1,sDate)) FROM CTE WHERE sDate > GETDATE()-29 ) SELECT * FROM CTE
プレ>
再帰的な CTE を使用できます:
;WITH CTE AS ( SELECT convert(date,GETDATE()) sDate, DATENAME(DW, GETDATE()) sDayofWeek UNION ALL SELECT DATEADD(DAY,-1,sDate), DATENAME(DW, DATEADD(DAY,-1,sDate)) FROM CTE WHERE sDate > GETDATE()-29 ) SELECT * FROM CTE
プレ>