我有一個報告來檢查重複的「recs」,但有一點丟失,並得到一個錯誤。看一看!SQL報告錯誤在哪裏
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'附近的語法不正確。 Wheres錯誤的語法?
在此先感謝!
該部分工作得很好 – 2012-04-13 11:03:45
!=是一個有效的運算符。 – 2012-04-13 11:05:51