我在sql服务器上有一个存储过程,其代码如下:
USE [MASS]
GO
/****** Object: StoredProcedure [dbo].[DossierEmailSend] Script Date: 05/11/2019 17:36:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[DossierEmailSend]
AS
--Create a holding table for the dossiers that met the criteria
DECLARE @dossiers TABLE (col1 varchar(100), col2 varchar(100), col3 varchar(100), col4 varchar(100));
--Insert the dossiers that met the criteria
INSERT INTO @dossiers
SELECT no, nome, obrano, convert(varchar,datafinal) col4
FROM bo
WHERE nmdos LIKE '%preço%'
AND datafinal = DATEADD(day, -1, CONVERT(date, GETDATE()))
--Create a row check to determine whether to send the email or not
DECLARE @rows int;
SET @rows = (SELECT COUNT(*) FROM @dossiers)
--Set the body elements
DECLARE @message varchar(1000);
-- declare the xml data to pass to the HTML body
DECLARE @xml NVARCHAR(MAX);
-- body will hold the HTML formatted table in the email
DECLARE @body NVARCHAR(MAX);
--Create the columns that will hold each row of data as xml
SET @xml = CAST(( SELECT col1 AS 'td','',col2 AS 'td','', col3 AS 'td','', col4 AS 'td'
FROM @dossiers
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
--Set the HTML for the body
SET @body ='<html><body><H3>Dossier Info</H3>
<table border = 1>
<tr>
<th> Num </th> <th> Nome </th> <th> Dossier </th> <th> Data de Fecho </th></tr>'
--Stitch everything together, appending the HTML table
SET @body = @body + @xml +'</table></body></html>'
SET NOCOUNT ON
--Check if any dossiers met the criteria
IF @rows > 0
BEGIN
--Send the email and append the data table to the body
EXEC dbo.uspSendEmail 'Encerramento Dossier Preços', 'ssantos@mass.pt', @body, NULL, 'filipeferreira@mass.pt'
SET NOCOUNT OFF
END
要运行此过程,我创建了一个作业,该任务会提取此过程,但事实是它没有运行。在工作属性上,我已设置:
对于成功操作,请退出报告成功的作业,而对于失败操作,请退出同一件事。我真的不知道错误是否在这里,对此家伙有何想法?