Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Passing Parameter to a Trigger

Author  Topic 

8022421
Starting Member

45 Posts

Posted - 2010-09-20 : 03:08:00
Iam deleting a record from a table which has 8 columns. At this time, I need to capture this record in the Delete Audit table which has 10 columns. Iam writing a trigger for this purpose. Out of these 10 columns, I can get the values of 8 columns. But the remaining 2 column values need to be passed from the front-end. Is there any way I can pass the values from the front-end to the trigger.

PavanKK
Starting Member

32 Posts

Posted - 2010-09-20 : 03:26:05
Instead of writing a trigger you can use OUTPUT INTO clause to insert those values directly from DELETE statement into Audit table. Check BOL for OUTPUT syntax



KK
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-21 : 12:24:10
what are those fields actually? didnt understand what extra information you're trying to add to audit?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-21 : 12:34:49
quote:
Originally posted by 8022421
Is there any way I can pass the values from the front-end to the trigger.



No. Where does the data exists? Can't you just join to it?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2010-09-21 : 13:05:02
You'll need to add those two columns to the table.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-09-21 : 13:07:31
I don't like this idea, but mention it in case of any benefit.

Create a VIEW that has the normal columns, plus the two extra columns, insert into that, and then create an INSTEAD OF trigger on the View.

We used INSTEAD OF triggers on Views for a while, but got fed up with the limitations and workaround that were needed (like problems when the underlying table included COMPUTED columns and so on) that we gave up on them ... hence why I wouldn't start with this ... but it might just solve this particular problem
Go to Top of Page
   

- Advertisement -