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
 [RESOLVED] Problem with Conditional Statement

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 ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Description: Sends Various Emails for the Website
-- =============================================
Create PROCEDURE sp_SendMail
@SendTo varchar(128),
@MessageToSend tinyint
AS

DECLARE @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'

BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'CellSaviorMail',
@recipients=@SendTo,
@subject = @Subject,
@body = @Message,
@body_format = 'HTML' ;


END
GO


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 in
IF @MessageToSend = 1
begin
--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
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -