we have an update trigger that inserts a row into a database...we wanted to make that part be dynamic enough so the trigger could automatically handle changes to the table.
What I did was create a stored procedure that would return all the fields of the table, except the "change fields" we created. We then dynamically build the insert stable including values for the "change fields" and fire it off using EXEC ().
The problem is EXEC () is complaining that the table 'deleted' does not exist. This is really the last piece of the puzzle for us ... is there anyway to do what we're looking for ??
-Christian
example :
What I did was create a stored procedure that would return all the fields of the table, except the "change fields" we created. We then dynamically build the insert stable including values for the "change fields" and fire it off using EXEC ().
The problem is EXEC () is complaining that the table 'deleted' does not exist. This is really the last piece of the puzzle for us ... is there anyway to do what we're looking for ??
-Christian
example :
Code:
exec usp_GenUpdateSQL @TableName = 'Users', @ColNames = @UserColNames output
set @UpdSQL = 'insert into Users select ' + @UserColNames + ',''Y'' as change_ind, getdate() as change_date, 12 as change_who from deleted'
exec (@UpdSQL)