错误:没有结果行集与此查询的执行相关联

时间:2015-11-11 11:52:06

标签: sql-server ssis runtime-error constraints

查询应该作为变量存储在"执行SQL任务":

Use [Reporting]
Go

DECLARE 
@current_month DATETIME, 
@current_year DATETIME, 
@current_year_final AS INT, 
@previous_period_final VARCHAR(2),
@test_period AS VARCHAR (2),
@previous_period_final_2 VARCHAR(2)

SET @current_month = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()),0)
SET @current_year = DATEADD(YEAR,DATEDIFF(YEAR,0,GETDATE()),0)
SET @current_year_final = CASE WHEN LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),4),2) = '01' THEN LEFT(CONVERT(VARCHAR,@current_year,112),4)-1 ELSE LEFT(CONVERT(VARCHAR,@current_year,112),4) END
SET @previous_period_final = CASE
 WHEN CAST(LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),4),2) AS INT) - 1 BETWEEN 10 AND 11 THEN  CAST(CAST(LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),4),2) AS INT) - 1 AS VARCHAR)  -- Type Varchar
 WHEN CAST(LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),3),1) AS INT) - 1 BETWEEN 1  AND 8  THEN '0' + CAST(CAST(LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),3),1) AS INT) - 1 AS VARCHAR)
 WHEN CAST(LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),4),2) AS INT) - 1 = 9 THEN '09'
 WHEN      LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),4),2) = '01'          THEN '12'
 ELSE 'Invalid formula' END
SET @previous_period_final_2 = CAST(LEFT(RIGHT(CONVERT(VARCHAR, GETDATE(),112),4),2) AS INT) - 1 

-- ### Returns: 
--    1 = 'identical' = row numbers match
--    0 = 'mis-matched' = row numbers do not match
select sum(rows_identical) as rows from

(
select CAST(CAST(case when count_rows_raw = count_rows_facts then 1 else 0 end as bit)as int) as rows_identical 
--,SQL_VARIANT_PROPERTY(CAST(CAST(case when count_rows_raw = count_rows_facts then 1 else 0 end as bit)as int),'BaseType') -- ### EXCELLENT WAY TO RETRIEVE DATATYPE ###
from
(
 select
 (
  select SUM(#rows_facts) as #rows_facts from 
  (            
   select COUNT(ID) as #rows_facts, 'finalized_entries_facts_table' as type from facts_reporting  
 where YearMonthID in (select YearMonthID from dim_year_month as yyMM  
        where yyMM.YearMonth = CAST(@current_year_final AS Varchar)+'_'+CAST(@previous_period_final AS Varchar))
 and SourceID IN (select SourceID from dbo.dim_source where Source = 'Unlocks')

union

   select COUNT(ID) as #rows_facts, 'missing_entries_facts_table' as type from missing_ids_Unlocks_raw 
 where YearMonthID in (select YearMonthID from dim_year_month as yyMM  
        where yyMM.YearMonth = CAST(@current_year_final AS Varchar)+'_'+CAST(@previous_period_final AS Varchar))
 and SourceID IN (select SourceID from dbo.dim_source where Source = 'Unlocks')         
  ) as rows
 ) as count_rows_facts,
 (
SELECT count(*)as #rows_raw from UnlocksRawCSV_table as raw
Where Year_Month_inserted = CAST(@current_year_final AS Varchar) + '_' + @previous_period_final
 ) as count_rows_raw
)
as row_checks
)
as count_check 
--where rows_identical <> 0

SSIS中的变量定义和结果集映射: enter image description here

在执行SQL任务中,我选择了&#34;结果集=单行&#34;。我也试过&#34;无&#34;。我在执行SQL任务上放了一个后执行断点,然后得到:

enter image description here

==如果我直接在SQL Server中执行此查询(见上文),我获得1时,为什么我在SSIS中获得0值?

后续任务中的优先约束如下所示:

enter image description here

编辑1:将此表达式更改为@RowCheck == 0不会改变任何内容,因为执行时任务仍然失败并出现相同的错误:

  

错误:没有结果行集与此查询的执行相关联

编辑:2:更改优先约束编辑器中的值&#34;成功&#34;到&#34;失败&#34;有效,但我不明白为什么任务本身失败以及为什么它会产生上述错误信息?但是,尽管继续使用包,但为变量RowCheck显示的值没有任何意义,因为它始终为零,无论Query返回...

编辑3:执行SQL语句的常规选项卡屏幕(我也尝试了&#34;单行&#34;以及上面提到的结果集映射:

enter image description here

0 个答案:

没有答案