我有以下查询,它获取具有给定条件的记录。下面展示了表中的两条记录以及查询的结果。我想要的是根据该EntryDate
列获取最近发生的事件。
0 A 2012-08-09 00:00:00.000 N0206527 N0168639 NULL 09 420202 LTD False
0 A 2012-08-08 00:00:00.000 N0206527 N0168639 NULL 09 420202 LTD False
DCMNumber CustomerDivision CustomerSerial Product PriorNonDenied
N0064819 09 420202 LTD 2
SET @firstDayOfCurrentMonth = DATEADD(m,DATEDIFF(M,0,GETDATE()),0)
SELECT DCMNumber, CustomerDivision, CustomerSerial, Product, COUNT(*) AS PriorNonDenied
FROM cauAssignedClaim
WHERE RecordType = 'A' AND
EscFromSTD = '0' AND
([Status] <> 'DE' OR
[Status] IS NULL) AND
CONVERT(VARCHAR(10), EntryDate, 110) BETWEEN
CASE WHEN Product = 'LTD' THEN CONVERT(VARCHAR(10), @firstDayOfCurrentMonth, 110)
ELSE CONVERT(VARCHAR(10), DATEADD(Day, -7, GETDATE()-1), 110)
END
AND CONVERT(VARCHAR(10), GETDATE()-1, 110)
GROUP BY [Status],
DCMNumber,
CustomerDivision,
CustomerSerial,
Product
谢谢,布拉德