此报告使用向下钻取将数据从顶部按周汇总到几天。现在,我只是从日期中提取日期部分,以便我可以对表进行分组,并且它可以很好地工作然而,一周的第一天设置为7,或者星期日,我需要它从1开始,或星期一。我读过的显而易见的解决方案是SET DATEFIRST 1
- 顺便说一句,当我尝试使用SET
时,我收到一条错误消息,说明它不受支持
我已经读过您可以更改报告的全局设置来执行此操作 - 但我不知道在哪里,并且如果可能的话,我希望能够在此查询中本地执行此操作。另外,我对@@DATEFIRST
进行了修改,但当然,它只是报告一周的第一天是7。
SELECT DATENAME(week, CAST(Date AS date)) AS week, DATENAME(dw, CAST(Date AS date)) AS day, CONVERT(date, Date, 103) AS date, FROM_NUMBER, DURATION,
TYPE_OF_CALL, ID, DATEPART(dw, CAST(Date - 1 AS date)) AS dayCode
FROM CallCenterStatsCDR
WHERE (Date BETWEEN @StartDate AND @EndDate)
GROUP BY DATENAME(week, CAST(Date AS date)), CONVERT(date, Date, 103), DATENAME(dw, CAST(Date AS date)), FROM_NUMBER, DURATION, TYPE_OF_CALL, ID,
DATEPART(dw, CAST(Date - 1 AS date))
ORDER BY Date DESC
答案 0 :(得分:1)
datefirst函数将影响服务器上运行的所有进程。您可以在查询中的所有日期字段中添加DateAdd(dd,1,YourDate)以获得相同的结果吗?