New to SQL, so bear with me please guys. I have a table 'ORDERS' that contains a field 'Comit'. When the Comit field is updated, if the field is set to 1 (field is of type bit) then I wish to send an email. I'll figure the email bit later. I just want to know how to test the value of the Comit field beforehand in a trigger. Thanks in advance.
Seeing as I don't have schema, this is how you would detect that `AddressLine1` changed on the `Person.Address` table in AdventureWorks2008, and insert the relevant `AddressID`s into another table called `destination_table` CREATE TRIGGER trig_Address_update ON [Person].[Address] FOR UPDATE AS INSERT INTO destination_table (AddressID) SELECT [i].[AddressID] FROM [inserted] i INNER JOIN [deleted] d ON [i].[AddressID] = [d].[AddressID] WHERE [i].[AddressLine1] != [d].[AddressLine1]
Never send email from a trigger. Ever. There are far too many problems with that approach and no advantages. So I would question why you need a trigger at all in this scenario. How about writing a process which polls the table periodically and sends out the emails? Triggers should generally be used as a last resort. It's much better in most cases to put logic in regular procedures and manage all your data access through those procedures.