Pass a variable into a trigger

Posted by Codesleuth on Stack Overflow See other posts from Stack Overflow or by Codesleuth
Published on 2010-04-15T15:13:18Z Indexed on 2010/04/15 15:23 UTC
Read the original article Hit count: 270

I have a trigger which deals with some data for logging purposes like so:

CREATE TRIGGER trgDataUpdated
   ON tblData FOR UPDATE
AS 
BEGIN
    INSERT INTO tblLog ( ParentID, OldValue, NewValue, UserID )
    SELECT  deleted.ParentID, deleted.Value, inserted.Value, 
            @intUserID -- how can I pass this in?
    FROM    inserted INNER JOIN deleted ON inserted.ID = deleted.ID
END

How can I pass in the variable @intUserID into the above trigger, as in the following code:

DECLARE @intUserID int
SET @intUserID = 10

UPDATE tblData
SET    Value = @x

PS: I know I can't literally pass in @intUserID to the trigger, it was just used for illustration purposes.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2000