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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 send email if a specific word in the coulumn

Author  Topic 

haseena
Starting Member

2 Posts

Posted - 2009-04-21 : 19:36:05
Hello Friends,
Looking for a script which sends out an email if a column is updated
with a specific word in it. I tried something but unfortunately it is not working.I would really appreciate if someone helps me in this.

Thank You


My code

declare @ASCode varchar(100)
select @ASCode=AAStatusCode from Station.dbo.store
if @ASCode ='FAIL'

Begin
EXEC msdb.dbo.sp_send_dbmail
@recipients=N'haseena@yahoo.com',
@body=ascode is failed. TEST.. IGNORE',
@subject =ascode is failed. TEST IGNORE',
@profile_name ='haseena_SendEmail'
end

nr
SQLTeam MVY

12543 Posts

Posted - 2009-04-21 : 20:06:23
create a trigger to add a row to a table if that word exists and have a job which polls the table and sends the email.

The trigger will be something like

create trigger xxxx on xxxxx for update
as

if exists (select * from inserted where col like '%myword%')


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-04-21 : 20:08:53
ceate trigger xxxx on store for update
as
if exists (select * from inserted where AAStatusCode = 'FAIL'
begin
....
end

Better to insert a row into a table from the trigger and use a job to poll that table to send the email.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -