Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jackstow
Posting Yak Master
160 Posts |
Posted - 2001-11-07 : 06:59:54
|
| I have a scipt that sends an email from Sql Server 2000 - it works fine when I run it from query analyzer and it works fine in a job I have set up. However, I'm trying to get it to work as a trigger with no success. The idea is to have an email sent when an insert takes place. Here is the code - any ideas? -CREATE TRIGGER email_alert ON tableFOR INSERTASDECLARE @bodytext varchar(1000)DECLARE @object intDECLARE @hr intDECLARE @count intSELECT @count = COUNT(*) FROM INSERTED IF @count > 0BEGIN--send emailSET @bodytext = 'email alert'EXEC @hr = sp_OACreate 'CDONTS.NewMail', @object OUTEXEC @hr = sp_OASetProperty @object, 'From', 'email address here'EXEC @hr = sp_OASetProperty @object, 'Body', @bodytextEXEC @hr = sp_OASetProperty @object, 'Subject','::: email alert ::::'EXEC @hr = sp_OASetProperty @object, 'To', 'email address here'EXEC @hr = sp_OAMethod @object, 'Send', NULLEXEC @hr = sp_OADestroy @objectEND |
|
|
|
|
|