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 |
|
coldfiretech
Starting Member
30 Posts |
Posted - 2009-04-11 : 13:48:35
|
Im trying to build a stored procedure to handle sending out various emails for our website.. I am having problems with my IF statement..It sets the message accordingly, but the subject of the email is always getting the 2nd one.. example, if i send the new account email, i get the new account message, but i get the account activation subject.Please help me fix this issue.SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Description: Sends Various Emails for the Website-- =============================================Create PROCEDURE sp_SendMail @SendTo varchar(128), @MessageToSend tinyint ASDECLARE @Message varchar(max)DECLARE @Subject varchar(100)IF @MessageToSend = 1 --Send New Account Email SET @Message = N'Welcome To Cell Savior.' SET @Subject = N'New Cell Savior Account' IF @MessageToSend = 2 --Send Account Activation Email SET @Message = N'Your Account has been activated.' SET @Subject = N'Cell Savior Account Activation'BEGINEXEC msdb.dbo.sp_send_dbmail @profile_name = 'CellSaviorMail', @recipients=@SendTo, @subject = @Subject, @body = @Message, @body_format = 'HTML' ; ENDGO Sucess comes before work only in the dictionary. |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2009-04-11 : 14:03:04
|
Use begin and end, as inIF @MessageToSend = 1begin --Send New Account Email SET @Message = N'Welcome To Cell Savior.' SET @Subject = N'New Cell Savior Account'end IF @MessageToSend = 2 begin --Send Account Activation Email SET @Message = N'Your Account has been activated.' SET @Subject = N'Cell Savior Account Activation'end |
 |
|
|
coldfiretech
Starting Member
30 Posts |
Posted - 2009-04-11 : 14:19:53
|
| Thanks. That fixed it.Its always the small things :)Sucess comes before work only in the dictionary. |
 |
|
|
|
|
|