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 2000 Forums
 SQL Server Development (2000)
 How to pass a Parameter to Trigger ?

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2004-08-23 : 11:01:28

I am using this triger , but Instead System_user, I would like to get
the User from my Aplication (save in a LogTable the Name of the User who did and Update or Delete) not the Computer Name.

Is there anyway to do this?

Tks
Again
Carlos Lages





Insert Log.dbo.area

Select Getdate(), System_User , 'U', d.* from Deleted as D inner join inserted as I on I.PK = D.PK

UNION ALL

Select Getdate(), System_User , 'D', d.* from Deleted as D left join inserted as I on I.PK = D.PK where I.PK is NULL

CLages
Posting Yak Master

116 Posts

Posted - 2004-08-23 : 11:07:50
I found out this in a Search at this forum posted by somebody.
But are there any way to do this?

Clages



You can't pass values to a trigger that were not part of the INSERT or UPDATE operation.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-08-23 : 11:40:36
quote:
Originally posted by CLages





You can't pass values to a trigger that were not part of the INSERT or UPDATE operation.




au contraire

But it needs to be part of a sproc....


-- Define CONTEXT_INFO to the user_id. This is used by the Delete trigger to store in history the Id of the
-- user who is deleting the row
-- Need also to fix the trigger for this to work
DECLARE @BinVar varbinary(128)
SET @BinVar = CAST( REPLICATE( 0x20, 128 ) AS varbinary(128) )
select @BinVar = convert(varbinary(128),@User_Id)
SET CONTEXT_INFO @BinVar


Then in the trigger


Declare @DelBY char(8)
SELECT @DelBY = convert(varchar(8),context_info)
FROM master.dbo.sysprocesses
WHERE spid = @@SPID






Brett

8-)
Go to Top of Page

CLages
Posting Yak Master

116 Posts

Posted - 2004-08-23 : 14:23:13
Tks, works fine

Carlos Lages
Go to Top of Page
   

- Advertisement -