Попробуйте следующий пример кода
-- Temp table to track changes
DECLARE @tmpTable TABLE
(
[Id] INT IDENTITY(1,1)
,[Attribute] VARCHAR(10)
,[Action] VARCHAR(50)
,[OldValue] VARCHAR(50)
,[NEwValue] VARCHAR(50)
,[UserId] INT
,[ModifiedDate] DATETIME
)
-- Actual/Transaction table
DECLARE @tblMyTable TABLE
(
ID INT IDENTITY(1,1),
Name VARCHAR(50)
)
-- Sample insert query
INSERT INTO @tblMyTable
OUTPUT 'Name'
,'Inserted'
,NULL -- Old value is null
,inserted.Name
,1 -- user ID
,GETDATE()
INTO @tmpTable
VALUES ('New Name');
-- Sample update query
UPDATE @tblMyTable
SET Name = 'Updated Name'
OUTPUT
'Name'
,'Updated'
,deleted.Name -- Old value is null
,inserted.Name
,1 -- user ID
,GETDATE()
INTO @tmpTable
select * from @tblMyTable
select * from @tmpTable