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
 Add Condition to EXEC

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2009-05-22 : 09:37:32
How do I add a condition to this statement


EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'PTC',
@recipients = 'email@email.com',
@body = 'Invoices have started posting.',
@subject = 'Invoices have started posting' ;


I have a table that has a field called emailflag. Table is called Email.

If emailflag = 'N' then I want the above to be executed. If the flag is 'Y' I do not want the code above to be executed.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-22 : 10:39:32
[code]
declare @emailflag char(1)

select @emailflag = emailflag from email
if @emailflag = 'N'
begin

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'PTC',
@recipients = 'email@email.com',
@body = 'Invoices have started posting.',
@subject = 'Invoices have started posting'

end
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -