我有一份报告要检查重复的“recs”,但有点丢失并出现错误。看一看!
Declare @StartDate as Datetime
Declare @EndDate as Datetime
set @StartDate = GetDate()-14
set @EndDate = GetDate()
SELECT *
FROM (SELECT dupl.machID, dupl.Location, dupl.place, dupl.recNumber,
MIN(realdupl.rcTransDate)
AS Firstrec, MAX(realdupl.rcTransDate) AS Lastrec
FROM
(SELECT rc.rcmachID AS machID, ck.ckLocation AS Location,
ck.ckLocationplace AS place, rc.rcrecNum AS recNumber, COUNT(*) as
NoOfrecs
FROM
(SELECT rcmachID, rcrecNum, rcTransDate, rcturnaroundIndicator FROM
ProBatchHostDbSec.dbo.vatrecs (NOLOCK)
)
AS rc
INNER JOIN machConfig AS ck WITH (NOLOCK)
ON rc.rcmachID = ck.ckmachID
WHERE rc.rcturnaroundIndicator = 0
AND ck.ckProductionmach = 'Y'
AND ck.ckLocationplace = 'IN'
GROUP BY rc.rcmachID, ck.ckLocation,
ck.ckLocationplace, rc.rcrecNum
HAVING COUNT(*) > 1
) AS dupl
INNER JOIN
(SELECT rcmachID, rcrecNum, rcTransDate, rcturnaroundIndicator FROM
ProBatchHostDbSec.dbo.vatrecs
AND dupl.recNumber = realdupl.rcrecNum
GROUP BY dupl.machID, dupl.Location, dupl.place, dupl.recNumber
) AS temp
WHERE temp.Firstrec != temp.Lastrec
AND temp.Lastrec BETWEEN @StartDate AND @EndDate
ORDER BY temp.machID, temp.Lastrecdbo.vatrecs --WITH (NOLOCK)
GROUP BY dupl.machID, dupl.Location, dupl.place, dupl.recNumber
) AS temp
当我运行它时,我得到一个错误“关键字'WHERE'附近的语法不正确。” 哪里语法不正确??
提前致谢!