[英]Need assistance with stored procedure
我编写了一个存储过程来向收件人发送警报。 警报包含在该时间点尚未执行完整性测试的应用程序列表。 但我想让我的代码工作就像列表是空的意味着没有应用程序没有进行测试,它不应该触发警报。
目前,警报是使用空表触发的,仅与标题一起触发。
有人可以帮帮我吗? 提前致谢。
这是代码:
CREATE PROCEDURE [dbo].[sp_Alert_BellTV_Chip Report]
AS
declare @HtmlBody varchar(max) = null
select appname, metalplating
from v_Escalation_lvl_3
where LVL3_ESCLS = 'Bell TV'
BEGIN
create table dbo.##BellTV_Application(Position int identity(1,1),html varchar(max))
insert into dbo.##BellTV_Application(html)
select distinct('<tr style="color:White;background-color:#666666;white-space:nowrap;"><td>'+appname+'</td><td>'+metalplating+'</td></tr>')
from dbo.v_Escalation_lvl_3
where LVL3_ESCLS = 'Bell TV'
DECLARE @cnt_2 INT = 1;
declare @subject varchar(max)='Chip Report'
set @HtmlBody=''
set @HtmlBody='<table cellspacing="0" cellpadding="4" border="0" style="color:#333333;font-family:Century Gothic;width:50%;border-collapse:collapse;">
<tr><td>Hi</td></tr><tr><td></td></tr><tr><td colspan=\"2\">Could you please perform a sanity test for the below applications.</td></tr><tr><td></td></tr>
<tr style="color:White;background-color:#336699;"><td>Application Name</td><td>Metal Plating</td></tr>'
while @cnt_2 <=(select count(*) from dbo.##BellTV_Application)
begin
set @HtmlBody=@HtmlBody+(select html from dbo.##BellTV_Application where Position=@cnt_2)
SET @cnt_2 = @cnt_2 + 1;
end
set @HtmlBody=@HtmlBody+'<tr><td>Thanks </td></tr><tr><td>Sanity Tool</td></tr></table>'
select @HtmlBody
drop table dbo.##BellTV_Application
end
if @HtmlBody<>'' or @HtmlBody is not null
begin
declare @aemail varchar(Max)
set @aemail ='recipeints'
EXEC sp_sendEmailToStartTesting
@mailRecipients = @aemail,
@mailbody = @htmlbody,
@mailSubject = @subject
END
Go
怎么样的
BEGIN
create table dbo.##BellTV_Application(Position int identity(1,1),html varchar(max))
insert into dbo.##BellTV_Application(html)
select distinct('<tr style="color:White;background-color:#666666;white-space:nowrap;"><td>'+appname+'</td><td>'+metalplating+'</td></tr>')
from dbo.v_Escalation_lvl_3
where LVL3_ESCLS = 'Bell TV'
DECLARE @cnt_2 INT = 1;
DECLARE @cntTotal INT
SELECT @cntTotal = count(*) from dbo.##BellTV_Application
IF @cntTotal >0
BEGIN
declare @subject varchar(max)='Chip Report'
set @HtmlBody=''
set @HtmlBody='<table cellspacing="0" cellpadding="4" border="0" style="color:#333333;font-family:Century Gothic;width:50%;border-collapse:collapse;">
<tr><td>Hi</td></tr><tr><td></td></tr><tr><td colspan=\"2\">Could you please perform a sanity test for the below applications.</td></tr><tr><td></td></tr>
<tr style="color:White;background-color:#336699;"><td>Application Name</td><td>Metal Plating</td></tr>'
while @cnt_2 <=@cntTotal
begin
set @HtmlBody=@HtmlBody+(select html from dbo.##BellTV_Application where Position=@cnt_2)
SET @cnt_2 = @cnt_2 + 1;
end
set @HtmlBody=@HtmlBody+'<tr><td>Thanks </td></tr><tr><td>Sanity Tool</td></tr></table>'
select @HtmlBody
drop table dbo.##BellTV_Application
end
if @HtmlBody<>'' or @HtmlBody is not null
begin
declare @aemail varchar(Max)
set @aemail ='recipeints'
EXEC sp_sendEmailToStartTesting
@mailRecipients = @aemail,
@mailbody = @htmlbody,
@mailSubject = @subject
END END GO
我想不是检查@HtmlBody你应该检查@ cnt_2值(最初是1)
if @HtmlBody<>'' or @HtmlBody is not null
begin
..........
你应该用。
if @cnt_2>1
begin
..........
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.