June 28, 2002 at 5:25 am
I HAVE A TABLE EMP WITH COLUMNS EMPNO,ENAME,SALARY and also a column MOD_DATE
WHEN EVER I UPDATE SALARY COLUMN I WANT TO
MODIFY MOD_DATE COLUMN OF SAME ROW WITH THE CURRENT DATE AND TIME.How can i do this by using triggers.
Any one help would be highly appreciated.
June 28, 2002 at 5:40 am
First you have to decide what constitutes an update. If a user updates the column to the same value the Update() syntax will still be true. A better choice is to compare the inserted/deleted table values to see if truly has changed. If it has, just update the date column using an update statement.
Andy
June 28, 2002 at 5:47 am
CREATE TRIGGER [tg_Emp_Up] ON dbo.Emp
FOR UPDATE
AS
update Emp
set Mod_Date = getdate()
from Emp e
inner join Inserted i on e.EmpNo = i.EmpNo
inner join Deleted d on i.EmpNo = d.EmpNo
where i.Salary != d.Salary
Regards,
Andy Jones
.
June 28, 2002 at 6:02 am
Thanks you all guys for your help.
It works great now.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply