嗨,我有以下声明:
DECLARE @currentWEEK INT
DECLARE @previousWEEK INT
DECLARE @CURRENDATE DATETIME
DECLARE @PREVIOUSDATE DATETIME
SET @PREVIOUSDATE = YEAR(DATEADD(YEAR, -1, GETDATE()))
SET @CURRENDATE = GETDATE()
SET @currentWEEK = RIGHT(DATENAME(wk,'2013-05-17 00:00:00.000'),2)
SET @previousWEEK = RIGHT(DATENAME(wk,'2012-05-17 00:00:00.000'),2)
SELECT COUNT(*)
FROM vevents
WHERE RIGHT(DATENAME(wk,dbo.vEvents.DateCreated),2) = @currentWEEK
AND
YEAR(dbo.vEvents.DateCreated) = YEAR(@CURRENDATE)
SELECT COUNT(*)
FROM vevents
WHERE RIGHT(DATENAME(wk,dbo.vEvents.DateCreated),2) = @previousWEEK
AND
YEAR(dbo.vEvents.DateCreated) = @PREVIOUSDATE
本质上它比较给定一周内两个日期的总数,但我想结合给定日期的两个选择语句以返回单个记录集(例如 CURRENTYEARCOUNT 和 PREVIOUSYEARCOUNT)
非常感谢您的帮助