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
 prevent update sql '05

Author  Topic 

christoff
Starting Member

7 Posts

Posted - 2009-09-01 : 14:32:35
Greetings all-

I have a trigger that updates a [flag] field in a record whenever that record is updated and I want to ignore the flag update if the only field in that record being updated is a [TimeModified] field. Any help with this would be greatly appreciated. Thanks in advance.

C

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-09-01 : 14:36:46
Can you show the code for the trigger?
Go to Top of Page

christoff
Starting Member

7 Posts

Posted - 2009-09-01 : 15:20:55
This is what I am using to capture any changes to the record. The emailed field is the flag that I set to false (0) based on any changes. The program that updates these records will update the entire record anytime the info on the form is modified, but only changes the [TimeModified] field when the form is modified without new info added. I want that update to be ignored so the emailed flag will remain unchanged. Thanks for the help.


BEGIN

update so
set [emailed] = 0
from [ServiceOrder] so

inner join inserted i on so.id = i.id
inner join deleted d on so.id = d.id

where i.TicketNumber <> d.TicketNumber or
i.[Status] <> d.[Status] or
i.Priority <> d.Priority or
i.Category <> d.Category or
i.Job <> d.Job or
i.Regulated <> d.Regulated or
i.ServingArea <> d.ServingArea or
i.ServiceType <> d.ServiceType or
i.CustomerID <> d.CustomerID or
i.ReportedCode <> d.ReportedCode or
i.FoundCode <> d.FoundCode or
i.[Notes] <> d.[Notes] or
i.TimeOpened <> d.TimeOpened or
i.TimeAssigned <> d.TimeAssigned or
i.TimeDispatched <> d.TimeDispatched or
i.TimeCleared <> d.TimeCleared or
i.TimeClosed <> d.TimeClosed or
i.TimeDeferred <> d.TimeDeferred or
i.TimeDisabled <> d.TimeDisabled or
i.TimeModified <> d.TimeModified or
i.CreatedBy <> d.CreatedBy or
i.ModifiedBy <> d.ModifiedBy or
i.ReportedBy <> d.ReportedBy or
i.AssignedTo <> d.AssignedTo or
i.ReportedTo <> d.ReportedTo or
i.TroubleFound <> d.TroubleFound or
i.PlantLink <> d.PlantLink or
i.Terminal <> d.Terminal or
i.SA <> d.SA or
i.Cable <> d.Cable or
i.Pair <> d.Pair or
i.[LEN] <> d.[LEN] or
i.CreationDate <> d.CreationDate or
i.FieldNotes <> d.FieldNotes or
i.History <> d.History or
i.ServiceTrans <> d.ServiceTrans or
i.MACC_ADD_UID <> d.MACC_ADD_UID or
i.flag <> d.flag or
i.maccnotes <> d.maccnotes
i.NewTicket <> d.NewTicket


END
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-02 : 05:09:48
then make use of COLUMNS_UPDATED function and check if only timemodified column is updated and add logic if otherwise

http://msdn.microsoft.com/en-us/library/ms186329.aspx
Go to Top of Page

christoff
Starting Member

7 Posts

Posted - 2009-09-03 : 15:25:25
Thanks for your feedback. I have used your suggestion with some success.

C
Go to Top of Page
   

- Advertisement -