DELETE into an OUTPUT table

DECLARE @items TABLE (itemnmbr varchar(20), quantity INT, cost NUMERIC(10,2))
INSERT INTO @items (itemnmbr, quantity, cost) values ('hammer',5,10.23)
INSERT INTO @items (itemnmbr, quantity, cost) values ('wrench',4,10.23)
INSERT INTO @items (itemnmbr, quantity, cost) values ('pliers',3,10.23)
INSERT INTO @items (itemnmbr, quantity, cost) values ('hack saw',2,10.23)
INSERT INTO @items (itemnmbr, quantity, cost) values ('level',1,10.23)
 
DECLARE @del TABLE (itemnmbr VARCHAR(20))
 
DELETE from @items
    OUTPUT deleted.itemnmbr INTO @del
    WHERE itemnmbr = 'wrench'
 
SELECT * FROM @items
 
SELECT * FROM @del

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences