Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

write email firing trigger

Posted on 2003-03-13
4
Medium Priority
?
221 Views
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?
0
Comment
Question by:delboy10
3 Comments
 
LVL 143

Accepted Solution

by:
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
FOR UPDATE
AS
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 ...
GO
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.

CHeers
 
0
 

Expert Comment

by:CleanupPing
ID: 9275913
delboy10:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 12

Expert Comment

by:monosodiumg
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.

monosodiumg
EE Cleanup Volunteer
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

571 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