0
當我嘗試運行此刪除了記錄計數記錄
DECLARE @by varchar(20) = 'Myself'
INSERT INTO dbo.MiscLog(LogType, onTable, Message, CreateBy)
SELECT
'Info', 'dbo.History',
'There are ' + CONVERT(varchar(20), COUNT(ID)) + ' old records being purged.', @by
FROM
(DELETE FROM dbo.History
OUTPUT deleted.ID
WHERE keyDate < dateadd(y, -7, getDate())) H
我得到
消息5322,級別15,狀態1,行5
一個聚集函數是不是在允許的SELECT子句包含嵌套的INSERT,UPDATE,DELETE或MERGE語句。