I have 2 tables like so:
JOBS table
Jobcode UserId Status
101 130 R
102 139 D
USERS table
UserId Email
130 test@example.com
I want to create a trigger on insert and update that sends an email to my stored procedure:
EXEC dbo.SendMyEmail @email, @jobcode;
when the jobcode is inserted as ‘D’ or updated to ‘D’.
I’m not sure about data types etc but this should at least put you on the right track.
Hope it helps…
EDIT:
Above code does not handle multiple updates, so for better practice see below option
Additionally, as discussed in the comments, sending emails from a trigger is also not the best, but as this is what the question asks for it has been included. I would recommend alternative options for sending emails such as a queue which has been mentioned in other answers.