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)
 providing/altering values in trigger

Author  Topic 

zkhb01
Starting Member

3 Posts

Posted - 2004-04-07 : 09:24:15
I have 4 audit columns in every table. Create userid and time stamp, and Update userid and time stamp. They are there for knowing who did what and when to a table row. I would like a trigger to provide the values if not provided by the insert or update. Here I would want to use the system date and system user.

Does SQL Server not let you alter values in triggers on the fly and have the row reflect this?

Karl

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-04-07 : 09:40:46
Yes.

UPDATE t
SET
t.val1=SYSTEM_USER(),
t.val2=GETDATE()
FROM
tbl t
INNER JOIN inserted i ON t.id = i.id

???

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

zkhb01
Starting Member

3 Posts

Posted - 2004-04-07 : 13:23:32
Can I do a test to verify the column is null on the inserted table? (table column definition has a default to set it to USER)

Karl
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-04-07 : 14:13:24
See ISNULL in Books Online.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -