| Author |
Topic |
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-05-26 : 12:14:32
|
Working with the following code. declare @emailflag char(1)select @emailflag = emailflag from emailif @emailflag = 'N'beginEXEC msdb.dbo.sp_send_dbmail @profile_name = 'PTC', @recipients = 'erin.vackert@estagroup.com', @body = 'Invoices have started posting.', @subject = 'Invoices have started posting'endupdate emailset emailflag = ' Y'end I only want the above code to run if my count is greater than 1. select count(*) as count from oehdrhst_sqlwhere posted_dt > dateadd(mi,-5,getdate()) |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2009-05-26 : 12:23:20
|
| [code]IF (select count(*) as count from oehdrhst_sql where posted_dt > dateadd(mi,-5,getdate()) ) > 1Begin declare @emailflag char(1) select @emailflag = emailflag from email if @emailflag = 'N' begin EXEC msdb.dbo.sp_send_dbmail @profile_name = 'PTC', @recipients = 'erin.vackert@estagroup.com', @body = 'Invoices have started posting.', @subject = 'Invoices have started posting' end update email set emailflag = ' Y' endEnd[/code]Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-05-26 : 12:48:10
|
| Here is what I have. at the very end where I have update emailset emailflag = 'Y'The flag is not updating. The script runs without any errors. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-26 : 12:53:46
|
| will email table be always having a single record? |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-05-26 : 12:53:54
|
Actually I had to change the beginning If statement as well. When I run the script I no longer get an email sent either.IF (select count(*) as count from oehdrhst_sql where month(posted_dt) = month(getdate()) and day(posted_dt) = day(getdate())and year(posted_dt) = year(getdate()))> 1BEGINdeclare @emailflag char(1)select @emailflag = emailflag from emailif @emailflag = 'N'beginEXEC msdb.dbo.sp_send_dbmail @profile_name = 'PTC', @recipients = 'erin.vackert@estagroup.com', @body = 'Invoices have started posting.', @subject = 'Invoices have started posting'endbeginupdate emailset emailflag = 'Y'endEND |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-05-26 : 12:54:35
|
| Yes. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-26 : 12:58:21
|
you've an extra begin end so its no longer inside if blockIF (select count(*) as count from oehdrhst_sql where month(posted_dt) = month(getdate()) and day(posted_dt) = day(getdate())and year(posted_dt) = year(getdate()))> 1BEGINdeclare @emailflag char(1)select @emailflag = emailflag from emailif @emailflag = 'N'beginEXEC msdb.dbo.sp_send_dbmail @profile_name = 'PTC', @recipients = 'erin.vackert@estagroup.com', @body = 'Invoices have started posting.', @subject = 'Invoices have started posting'endbeginupdate emailset emailflag = 'Y'endEND |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-05-26 : 13:04:09
|
| That didn't seem to do it. emailflag still set to 'N' |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-26 : 13:07:22
|
| was mail send atleast? |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-05-26 : 13:10:40
|
| Nope. Just retested and sent a test email and I received an email. So I know that part is setup correctly and working. If I only run this portion an email is sent as well:declare @emailflag char(1)select @emailflag = emailflag from emailif @emailflag = 'N'beginEXEC msdb.dbo.sp_send_dbmail @profile_name = 'PTC', @recipients = 'erin.vackert@estagroup.com', @body = 'Invoices have started posting.', @subject = 'Invoices have started posting'end |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-05-26 : 13:14:48
|
| I apologize. Stupid mistake on my part. In the beginning I needed "> 0" and not "> 1". I only had one record in the data I was testing against. Sorry for wasting your time.It is working now. Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-26 : 13:17:48
|
| cool..glad that you sorted it out |
 |
|
|
|