write email firing trigger

Posted on 2003-03-13
Medium Priority
Last Modified: 2006-11-17
I need to write a trigger that will fire off an email if a particular field value is changed to 1.

Any ideas?
Question by:delboy10
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 200 total points
ID: 8135265
basically, this is not a problem. use xp_sendmail to send emails, and use this inside the trigger:

CREATE TRIGGER yourtrigger
ON yourtable
IF EXISTS( select * from inserted i join deleted d on i.keyfield = d.keyfield where i.particularfield = 1 and (d.particularfield <> 1 or d.particularfield IS NULL) )
  exec master.dbo.xp_sendmail ...
Now, it's up to you to configure SQL Mail so it can be used, and to complete the arguments for xp_sendmail.

Note however that I never run xp_sendmail directly in a trigger, but insert a flag in another table, and let a job check this table regulary which then runs the xp_sendmail as needed.


Expert Comment

ID: 9275913
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
LVL 12

Expert Comment

ID: 11183186
No comment has been added to this question in more than 268 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: angelIII http:#8135265

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question