Solved

Trigger an email

Posted on 2001-08-01
5
195 Views
Last Modified: 2006-11-17
Using NT 4 and SQL 7.
Is it possible (and if so, how) to send an email when a certain field in a certain table changes?

I'm thinking like a trigger calling a stored procedure, or something like that.
0
Comment
Question by:JOK
[X]
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
5 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 100 total points
ID: 6342457
Look at xp_SendMail.  You might use it like this:

CREATE TRIGGER t_ItChanged ON MyTable FOR Update AS

If Update(MyColumn)
BEGIN
    EXEC xp_sendmail 'myemailaddress', 'The MyColumn field on ' + Cast(inserted.ID) + ' was changed from ' + deleted.MyColumn + ' to ' + inserted.MyColumn + '.'
END

 
0
 
LVL 3

Expert Comment

by:sachinb
ID: 6342575
What bhess1 has said is correct, but you will need to make sure that you have the SQL Mail configured on the server to send those mails.  These details would be available in the sql online books.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6343446
Furthermore, i recommend not to send emails directly in triggers, as this slows down the initial action, especially if there are email problems...

I suggest that you have separate tables where you mark that email(s) should be send (and why), and let a separate process (job) send the emails at regular intervals.

CHeers
0
 
LVL 3

Author Comment

by:JOK
ID: 6344613
Thanks for the comments. Its going to be a few days before I can get to try this. If you don't hear anything back by Wednesday (8/8) feel free to bug/remind me.
0
 
LVL 3

Author Comment

by:JOK
ID: 6413244
Thanks to all. Haven't finished yet, but I'm on the right track. Sorry for the delay. Giving points to the everyone because every little bit helped.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
If in a where clause in t-sql 7 49
Removing SCCM 2016 4 44
Replacing unrecognized function name in SQL Query 4 42
SQL syntax for max(date) 3 35
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

739 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