简体   繁体   English

SSIS执行SQL任务有效,但在执行报告中显示错误消息

[英]SSIS Execute SQL Task works but displays error message in execution report

My Execute SQL Task executes a stored procedure. 我的执行SQL任务执行存储过程。 If it gets some records, then proceeds to a task to create a report. 如果得到一些记录,则继续执行任务以创建报告。 Otherwise, it goes to a script task to send out an email. 否则,将执行脚本任务以发送电子邮件。 The ResultSet is set to "Single row". ResultSet设置为“单行”。

Everything works as expected. 一切正常。 However, when stored procedure does not return any rows, it still sends out an email, but creates a failed message in SQL Execution report. 但是,当存储过程不返回任何行时,它仍会发送电子邮件,但会在SQL执行报告中创建失败的消息。 The error message states: 错误消息指出:

An error occurred while assigning a value to variable "Variable": "Single Row result set is specified, but no rows were returned." 为变量“变量”赋值时发生错误:“指定了单行结果集,但未返回任何行。”

I cannot modify my stored procedure. 我无法修改存储过程。 What are my options to "fix" this error. 我有哪些“修复”此错误的选项。 (My package runs as expected.) (我的程序包按预期运行。)

You have to add some validation to your Execute SQL Task to avoid Empty ResultSets 您必须在Execute SQL Task添加一些验证,以避免结果集为空

  1. Insert result into a Temp Table 将结果插入临时表
  2. Check If the Temp Table contains Rows 检查临时表是否包含行
  3. If not Select an non significant Row 如果不是,请选择不重要的行

     CREATE #TempTable (Column0 Varchar(50), Column1 varchar(50), ....) INSERT INTO #TempTable EXEC Proc DECLARE @intCount INT SELECT @intCount = COUNT(*) FROM #TempTable IF @intCount > 0 SELECT TOP 1 * FROM #TempTable ELSE SELECT 0 
  4. Add An expression on The Send Mail Task ( If Not Empty Row --> Send Mail ) 在“发送邮件”任务上添加表达式( If Not Empty Row --> Send Mail

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM