我需要帮助来提出一个查询,该查询计算当前日期的总行数。我需要它每天自动更新当前日期。我每天都在使用Pentaho来运行总行数的工作,但是我很难查询它。下面的查询提供了当前日期,但是我的计数为0。我知道今天有行,所以不确定为什么它为0。
SELECT dateadd(day,datediff(day,0,GETDATE()),0) as
Received_Date2,COUNT(*) as Enrollments_Completed
FROM CCMDB.dbo.InboundCorrespondenceDetails CD,
CCMDB.dbo.ResolutionLetterDetails RD
WHERE CD.ccid = RD.ccid
and ReceivedDate >= dateadd(day,datediff(day,1,GETDATE()),0)
AND ReceivedDate < dateadd(day,datediff(day,0,GETDATE()),0)
AND CatID in('cat0014')
AND IncomingType <> 'RITS'
AND status = 'Completed'
答案 0 :(得分:0)
好像您的日期范围小于当前日期(dateadd(day,datediff(day,0,GETDATE()),0))。所以基本上,您正在尝试检索前一天的记录。
如果您需要当前日期的记录,则:
SELECT dateadd(day,datediff(day,0,GETDATE()),0) as
Received_Date2,COUNT(*) as Enrollments_Completed
FROM CCMDB.dbo.InboundCorrespondenceDetails CD,
CCMDB.dbo.ResolutionLetterDetails RD
WHERE CD.ccid = RD.ccid
and ReceivedDate >= DATEADD(d,DATEDIFF(d,0,getdate()),0)
AND ReceivedDate < DATEADD(d,DATEDIFF(d,0,getdate()+ 1),0)
AND CatID in('cat0014')
AND IncomingType <> 'RITS'
AND status = 'Completed'