Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

This is my stored procedure for sending email. It works fine. But how to check if condition inside html format

CREATE PROCEDURE [dbo].[Condition_Status] (@view nvarchar(30), @EMAIL CHAR(150)) AS
DECLARE @tableHTML NVARCHAR(MAX)
DECLARE @emailsubject char(150)



SET @tableHTML =
N'<BODY topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" style=" "bgcolor="#ffffff">'+ N'
'+
N'
' +
N''+
N''+
N''+
N''+
N'
'+

N''+

N'' +
N'' +
N''+
N'
' +

// here i want to use if condition based on @view parameter. @view parameter i will be passing value from database.
heading1 column is xxx
heading2 column is yyy

if @view contains xxx, i need to show heading1 and if @view contains yyy, i need to show heading2

Right now i am showing heading1 column see below select coding. But dynamically i need to show according to @view parameter.

N''+
cast((select isnull(heading1,'') from tab1 where email1=@EMAIL for xml path(''),type)as varchar(max)) +''+
' +

N'
' +







N'
'+
N'
'+
N'</BODY>'


select @tableHTML

set @emailsubject = 'Test#'+ convert(char(8), @EMAIL)

EXEC msdb.dbo.sp_send_dbmail @recipients = @EMAIL,
@profile_name = 'gmail',
@subject = @emailsubject,
@body = @tableHTML,
@body_format = 'HTML'
Posted
Comments
ArunRajendra 18-Jul-14 4:45am    
What condtion you want to check and what you want to do if condition is true.
christhuxavier 18-Jul-14 4:48am    
like this

if @view="xxx" then i need to show heading1 else need to show heading2

1 solution

If my understanding is correct, You can use the case statement in the select.
SQL
select (Case @view when 'xxx' then heading1 else heading2 end) from table

and put your remaining query
 
Share this answer
 
Comments
christhuxavier 22-Jul-14 23:38pm    
Thanks Mr.Kumarbs it works now..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900