Before you run this -- just think about what you expect to get out of the OUTPUT clause of the DELETE statement...Then try running it. SURPRISE!IF OBJECT_ID('tempdb..#foo') IS NOT NULL DROP TABLE #fooCREATE TABLE #foo ( [bar] CHAR(1) , [val] INT )INSERT #foo ( bar, val )VALUES ( 'A', 1) , ( 'A', 2) , ( 'B', 2) , ( 'A', 3) ; WITH delCTE AS ( SELECT * , ROW_NUMBER() OVER (PARTITION BY [bar] ORDER BY [val]) AS [rnk] FROM #foo )DELETE d OUTPUT DELETED.* FROM delCTE AS d WHERE d.[rnk] > 1SELECT * FROM #foo
Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/