My Manager is getting well annoyed with me about a trigger which I need to create.I want a trigger to fire when there has been an update to a certain column within a table. If there has been a change within this Column it will automatically send an email to the relevant people.My problem is creating the trigger. I am very new to SQL Server and have looked in a few books and on BOL but still can't work out how to do it.The trigger will fire when there has been a change in the date to a particular PartID from the previous DTS Import. Well, thats what I want to happen. Is this possible within SQL Server? I have been to other forums and they have come up with this code? The only thing is it does not execute properly. CREATE TRIGGER NewPartIDUpdate ON PartIDUpdateNTFOR UPDATE ASDECLARE @PartID int, @msg varchar(100)IF UPDATE (GGOPDT)BEGINSELECT @PartID = 0WHILE @PartID < (Select max(PartID) FROM InsertedBEGINSELECT @PartID = MIN(PartID) FROM Inserted WHERE PartID > @PartIDIF EXISTS (SELECT * FROM Inserted i, Deleted d WHERE i.PartID = d.PartID ANDi.PartID = @PartID AND i.GGOPDT <> d.GGOPDT)BEGINSELECT @msg = 'Part' + convert(varchar(20),@PartID) + 'Changed'EXEC Master..xp_sendmail @recipients = 'me@meltd.com,someoneelse@meltd.com', @subject = 'Part date change', @meggase = @msgENDENDEND
Any suggestions? My boss wants to see this trigger in action by tomorrow OR ELSE