Trigger mail on update or insert

  • Hi,

    I've searched the forums and through Google and found a lot of outdated stuff. MS SQL isn`t my daily job but I need it now one time.
    For our CRM system I need a trigger that sends an email on an update or insert in the employee table including the updated or inserted row.
    I know it's not the most prefered way, but there are no other options.

    Table: Employees
    a few of the fields for example: EmployeeID, EmployeeName, EmployeeLastName, EmployeeDepartment, EmployeeStatus

    When an employee is added, the CRM will insert the data into this table. When an employee leaves, the EmployeeStatus is changed.

    Can someone help me out please? With an example I will be able to convert that to a second table.

  • Try using a trigger, although you probably do not want to send an email directly from a trigger. 
    Create an insert trigger, when it fires, capture the relevant information for a new employee, and insert that into an "email queue" table.  Set up a SQL job that runs on a schedule that looks for new rows in this table, and sends the email if it finds one. 

    An update trigger can be created to do the same thing for the terminated employees.

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply