Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To create History table to record changes in fields
Message
From
13/07/2006 21:53:21
 
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01135878
Message ID:
01136288
Views:
10
I have written the trigger and within the trigger I am calling a stored procedure. Can I use the table names Inserted and Deleted in the stored procedure that is being called by the trigger. Is there any way to pass these if not available there?

Bharat, sorry to jump in, but I wanted to take a stab at this:

In SQL 2000, the Inserted and Deleted system tables are only visible inside a trigger. (This has changed in 2005).

You cannot "pass" tables as parameters. If you need the contents of the INSERTED and DELETED tables outside of the trigger, you need to SELECT them into Temporary Tables inside your trigger:
SELECT * INTO #TempInserted FROM Inserted
SELECT * INTO #TempDeleted FROM Deleted
And then you can reference #TempInserted and #TempDeleted in a stored procedure that's called by the trigger. However, there are some potential "gotchas", such as if you're using TEXT fields.

While this can be made to work....if I can ask, why specifically do you need to do this, especially if you're scripting your update triggers. Just curious.

Kevin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform