如何在数据库电子邮件存储过程中应用HTML中的条件 [英] How to apply if condition inside HTML in database email stored procedure

查看:102
本文介绍了如何在数据库电子邮件存储过程中应用HTML中的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





这是我发送电子邮件的存储过程。它工作正常。但是如何检查html格式中的条件



CREATE PROCEDURE [dbo]。[Condition_Status](@view nvarchar(30),@ MEMAIL CHAR(150))AS

DECLARE @tableHTML NVARCHAR(MAX)

DECLARE @emailsubject char(150)







SET @tableHTML =

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

'+

N'

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'
'+



//这里我想使用if条件基于@view参数。 @view参数我将从数据库传递值。

heading1列是xxx

heading2列是yyy



如果@view包含xxx,我需要显示heading1如果@view包含yyy,我需要显示heading2



现在我显示的是heading1列,请参阅下面的选择编码。但动态我需要根据@view参数显示。



N''+

cast((从tab1选择isnull(heading1,''),其中email1 = @ EMAIL for xml path(''),type)as varchar( max))+''+
'+



N'
'+ < br $>














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



设置@emailsubject ='测试#'+转换(char(8),@ emAIL)



EXEC msdb.dbo.sp_send_dbmail @recipients = @EMAIL,

@profile_name ='gmail',

@subject = @emailsubject,

@body = @tableHTML,
@body_format ='HTML'
'+
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'

推荐答案

如果我的理解是正确的,您可以在选择中使用case语句。

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



并将您剩余的查询


and put your remaining query


这篇关于如何在数据库电子邮件存储过程中应用HTML中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆