jeudi 16 juillet 2015

Need to create sql trigger that will send out html email to a customer

I need to set something up through sql server 2005, that will automatically send a welcome message to new customers. Through prophet 21, every time a new customer is entered into the system, they are given a unique 9-digit number by the system. These are stored in a table called "customer". My database email is already set up and I have a profile.

I'm thinking something like this should work?

    IF EXISTS (SELECT 1 FROM inserted WHERE (customer id is not already present in table))
    BEGIN
        EXEC msdb.dbo.sp_send_dbmail
          @recipients = 'whoever@customeremail.com', 
          @profile_name = 'P21 Alert',
          @subject = 'Welcome!',
          @body_format = 'HTML'
          @body = 'Thank you for ordering product <product ID>, welcome to our company';
    END
END
GO`    

Please help or point me in the right direction!

Aucun commentaire:

Enregistrer un commentaire