我有2天
Date_from 01/03/2011
Date_to 15/03/2011
如何从两个日期范围以上的特殊工作日(周一,周二和周五)?
我需要输出如下
Date_From Date_To
01/03/2011 01/03/2011 'Tuesday
04/03/2011 04/03/2011 'Friday
07/03/2011 08/03/2011 'Monday and Tuesday
11/03/2011 11/03/2011 'Friday
14/03/2011 15/03/2011 'Monday and Tuesday
答案 0 :(得分:3)
WITH wd (d) AS
(
SELECT 0
UNION ALL
SELECT d + 1
FROM wd
WHERE d < 6
)
SELECT d.date_from,
(
SELECT DATENAME(w, DATEADD(d, d, date_from)) + ' ' AS [text()]
FROM wd
WHERE DATEPART(w, DATEADD(d, d, date_from)) IN (2, 5, 6)
AND DATEADD(d, d, date_from) <= date_to
FOR XML PATH('')
)
FROM dates d
答案 1 :(得分:1)
答案 2 :(得分:1)
如果这是针对SQL Server执行此操作:
SELECT DATENAME(dw, GETDATE())