BEGIN TRANSACTION
DELETE FROM MessagesRead
WHERE [To] <> 'Feadmin'
AND [To] <> 'Catalonia'
AND [To] <> 'Bromordia'
AND [From] <> 'Feadmin'
AND [From] <> 'Catalonia'
AND [From] <> 'Bromordia'
AND MessageID IN (SELECT MessageID
FROM Messages
WHERE TickNr < ((SELECT TickNumber FROM CurrentTick)-1000))
AND Saved = 0 AND [Read] =1;
DELETE FROM Messages
WHERE MessageID NOT IN (SELECT DISTINCT MessageID FROM MessagesRead);
DELETE FROM MessagesAdmin
WHERE MessageID NOT IN (SELECT DISTINCT MessageID FROM Messages);
DELETE from DiscussionMessages
WHERE DATEDIFF(DAY,Inserted,CURRENT_TIMESTAMP) > 6000
COMMIT TRANSACTION
我剛剛從SQL Server 2012升級到2014年我跑已經工作上面的存儲過程到現在爲止收到錯誤消息:SQL - 子查詢返回多個值
消息512,級別16,狀態1,過程Engine_DeleteMessages,第9行
子查詢返回多個值。當子查詢遵循=,!=,<,< =,>,> =或當子查詢用作表達式時,這是不允許的。
我明明已經制定了不應該說WHERE TickNr <
但我想不出更好的方式來這個詞,或者爲什麼它工作,直到我升級?
它看起來像你的舊數據沒有重複。 IN聲明爲您提供了返回大量記錄的機會,大部分聲明也是如此。也許添加一個Distinct到MessageID IN(SELECT ...)? – 2015-03-24 21:28:13