October 7, 2008 at 10:18 am
I have a table called [dbo].[timedes] with 5 columns (id, lastname, firstname, status, modifieddate)
I want to update modifieddate to today’s date when every there is a modification to any field except the status field
So I created a trigger
create TRIGGER [trigdate] ON [dbo].[timedes]
AFTER UPDATE AS
BEGIN
SET NOCOUNT ON;
if not update (status)
begin
UPDATE dbo.timedes
SET dbo.timedes.modifieydate = GETDATE()
from inserted
WHERE inserted.id = timedes.id ;
end ;
end
but its not updating the modifieydate even when lastname or firstname changes and really need help
October 7, 2008 at 10:32 am
mesql (10/7/2008)
I have a table called [dbo].[timedes] with 5 columns (id, lastname, firstname, status, modifieddate)I want to update modifieddate to today’s date when every there is a modification to any field except the status field
So I created a trigger
create TRIGGER [trigdate] ON [dbo].[timedes]
AFTER UPDATE AS
BEGIN
SET NOCOUNT ON;
if not update (status)
begin
UPDATE dbo.timedes
SET dbo.timedes.modifieydate = GETDATE()
from inserted
WHERE inserted.id = timedes.id ;
end ;
end
but its not updating the modifieydate even when lastname or firstname changes and really need help
Try this:
create TRIGGER [trigdate] ON [dbo].[timedes]
AFTER UPDATE AS
BEGIN
SET NOCOUNT ON;
if (update (lastname) or update(firstname))
begin
UPDATE dbo.timedes
SET dbo.timedes.modifieydate = GETDATE()
from inserted
WHERE inserted.id = timedes.id ;
end ;
end
😎
October 7, 2008 at 11:17 am
I think Lynn probably has an answer that works, so I'll just say that I'm glad the trigger will is written to handle sets. That's rare in these forums, it seems.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply