Discussion Locked

SQL Server, Trigger -> Variable Table

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How can i perform an insert, using the deleted table in a MS SQL server 2000 Trigger? I want to pass the name of the receiving table as a variable. The following does not work.

Create Trigger [CRF_01_AbioScoreAudit] On dbo.CRF_01_AbioScore
For Delete, Insert, Update as
Declare @AuditTabName VarChar(60)
Set @AuditTabName= 'CRF_01_AbioScore_Audit'
Insert Into @AuditTabName
Select GetTime(),'Inserted', Current_User,* From Deleted

1 reply

by geert pante

The reason why you can't do this is clear:
in transact-SQL, the argument Xxx in the statement 'INSERT INTO Xxx' should be a table (or perhaps a cursor), and you declared it a varchar.

This should work, but I'm sure you are aware of it:
Insert Into CRF_01_AbioScore_Audit
Select GetTime(),'Inserted', Current_User,* From Deleted

Anyway, I don't see your point. Should the trigger for one table insert into a variable table? Or do you want to create a generic trigger? That won't work, since the 'Deleted' table is only available for the current trigger scope.

Greetings, Geert.

This discussion is closed to new replies.