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
 General SQL Server Forums
 New to SQL Server Programming
 Create an Update Trigger

Author  Topic 

naumangee
Starting Member

2 Posts

Posted - 2008-05-08 : 11:06:29
Hi,
I have a table with somefields, here i will only mention on which i need to perform an action, possibly with the use of Trigger.

Fields = Active, inactiveDate
Active Field is of bit datatype mean conatins 1 or 0,
1 means the user is active, but when i change the active field to 0, and make the user inactive i want the date to be populated automatically to inactiveDate field when active field is changed to 0.

any help is much appreciated

NAUMAN

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-08 : 11:26:51
[code]CREATE TRIGGER YourTrigger ON YourTable
AFTER UPDATE
AS
BEGIN
UPDATE t
SET t.InactiveDate=GETDATE()
FROM YourTable t
INNER JOIN INSERTED i
ON i.PKCol=t.PKCol
WHERE i.Active=1
END[/code]
Go to Top of Page

naumangee
Starting Member

2 Posts

Posted - 2008-05-08 : 11:45:46
Thank you so much Visakh.

It's perfect.

NAUMAN
Go to Top of Page
   

- Advertisement -