SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 How to apply if condition inside HTML in database
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

christxavier
Starting Member

India
1 Posts

Posted - 07/18/2014 :  04:38:34  Show Profile  Reply with Quote
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'<CENTER>'+
N'<div align="center">' +
N'<table cellpadding="0" cellspacing="0" width="820" bordercolor="#464646" style=" border-border-border-right: 1px solid #464646; border-bottom:2px solid #464646;">'+
N'<tr>'+
N'<td>'+

N'<table cellpadding="0" cellspacing="0" width="820" bgcolor="#f3f3f3">'+

N'<TR>' +
N'<td colspan="3" align="center">' +

// 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'<span style=font-size:17pt;font-family:Calibri;color:#4e4e4e;font-weight:bold;>'+
cast((select isnull(heading1,'') from tab1 where email1=@EMAIL for xml path(''),type)as varchar(max)) +'</p>'+</span>' +

N'</td>' +
N'</TR>'+
N'</TABLE>' +







N'</td>'+
N'</tr>'+
N'</table>'+
N'<div>'+
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'

christ

SwePeso
Patron Saint of Lost Yaks

Sweden
30282 Posts

Posted - 07/18/2014 :  05:25:07  Show Profile  Visit SwePeso's Homepage  Reply with Quote
You can use a CASE statements to investigate your values.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000