Here I use the AdventureWorks sample database to show the sample T SQL for OUTPUT clause.
USE AdventureWorks;
BEGIN TRANSACTION;
DECLARE @testoutput TABLE
(
SalesOrderID int
, SalesOrderDetailID int
, QtyBefore int
, QtyAfter int
, ModifiedDate datetime2
, UserName varchar(30)
)
SELECT * FROM @testoutput;
UPDATE Sales.SalesOrderDetail
SET OrderQty = 5
OUTPUT inserted.SalesOrderID
, inserted.SalesOrderDetailID
, deleted.OrderQty
, inserted.OrderQty
, GETDATE()
, SUSER_NAME()
INTO @testoutput
WHERE SalesOrderID = 43659 AND SalesOrderDetailID = 1;
SELECT * FROM @testoutput;
ROLLBACK TRANSACTION;
SELECT OrderQty FROM Sales.SalesOrderDetail WHERE SalesOrderID = 43659 AND SalesOrderDetailID = 1;
No comments:
Post a Comment