这是一个非常丑陋的查询,可以为您提供结果:
SELECT row_number () OVER (ORDER BY DateD), *
FROM
(
SELECT DATENAME (dw, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) AS 'DateName',
DATEADD(month, DATEDIFF(month, 0, getdate()), 0) AS 'DateD'
UNION
SELECT DATENAME (dw, DateAdd(day, 1, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))) AS 'DateName',
DateAdd(day, 1, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) AS 'DateD'
UNION
SELECT DATENAME (dw, DateAdd(day, 2, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))) AS 'DateName',
DateAdd(day, 2, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) AS 'DateD'
UNION
SELECT DATENAME (dw, DateAdd(day, 3, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))) AS 'DateName',
DateAdd(day, 3, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) AS 'DateD'
UNION
SELECT DATENAME (dw, DateAdd(day, 4, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))) AS 'DateName',
DateAdd(day, 4, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) AS 'DateD'
UNION
SELECT DATENAME (dw, DateAdd(day, 5, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))) AS 'DateName',
DateAdd(day, 5, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) AS 'DateD'
UNION
SELECT DATENAME (dw, DateAdd(day, 6, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))) AS 'DateName',
DateAdd(day, 6, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) AS 'DateD'
) queryTable
请参阅带有演示的 SQL Fiddle