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.
| 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 getthe 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?TksAgainCarlos LagesInsert Log.dbo.areaSelect Getdate(), System_User , 'U', d.* from Deleted as D inner join inserted as I on I.PK = D.PKUNION ALLSelect 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?ClagesYou can't pass values to a trigger that were not part of the INSERT or UPDATE operation. |
 |
|
|
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 contraireBut 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 Brett8-) |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2004-08-23 : 14:23:13
|
| Tks, works fineCarlos Lages |
 |
|
|
|
|
|
|
|