我在使用 datepart 的查询中遇到了一个问题。我们一直在使用以下查询来返回最近三周的数据,但是我们最近发现公司使用的是周一至周日的报告周,而以下查询默认为周日至周六。我已经尝试过"SET LANGUAGE BRITISH"
,"SET DATEFIRST 1"
但我不能很好地掌握这些功能,因为它们不会改变我的查询结果。我应该提到我们在 sql server 2000 上运行。如果您知道解决方案,我们将不胜感激:
declare @name varchar(50);
set @name = 'A name here';
SELECT week, year, CallCount, GoodCalls, CAST(CAST(GoodCalls as float)/CAST(CallCount as float)as decimal (18,4)) as NCP_perc
FROM
(SELECT TOP 3 datepart(ww, a.date_c) as week
,datepart(year, a.date_c) as year
,SUM(CallCount_wo_Xfer) as CallCount
,ROUND(SUM(CAST((CallCount_wo_Xfer*NCP_wo_Xfer)as float)),0) as GoodCalls
FROM db1 A
inner join db2 B
on a.Agent = b.Name collate database_default
inner join db3 C
on b.id = c.id collate database_default
where c.manager = @name
group by datepart(year, a.date_c), datepart(ww, a.date_c)) AS T
order by year desc, week desc