title: Error: No result rowset is associated with the execution of this query
body: <p>Query which should be stored as variable in "Execute SQL Task":</p>
  
  <pre><code>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 &lt;&gt; 0
  </code></pre>
  
  <p>Variable definition and Result Set mapping in SSIS:
  <a href="https://i.stack.imgur.com/ABFeR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ABFeR.png" alt="enter image description here"></a></p>
  
  <p>In the Execute SQL Task I have selected "Result Set = Single row". I have also tried "None". I have put a post-execute Breakpoint on the Execute SQL Task and get this:</p>
  
  <p><a href="https://i.stack.imgur.com/lFF4s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lFF4s.png" alt="enter image description here"></a></p>
  
  <p>== Why am I getting a 0 as value in SSIS while I am getting a 1 if I execute this query (see above) in SQL Server directly?</p>
  
  <p>The precedence constraint in the subsequent task look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/fkY7o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fkY7o.png" alt="enter image description here"></a></p>
  
  <p>EDIT 1: Changing this expression to <code>@RowCheck == 0</code> does not change anything as the task still fails on execution with the same error:</p>
  
  <blockquote>
    <p>Error: No result rowset is associated with the execution of this query</p>
  </blockquote>
  
  <p>EDIT: 2: Changing the Value in the Precedence Constraint Editor from "Success" to "Failure" works but I don't understand why the task itself fails and why it generates the above mentioned error message? However, despite proceeding with the package the value displayed for variable RowCheck does not make any sense as it is always zero, regardless of that the Query returns...</p>
  
  <p>EDIT 3: Screen of General Tab for Execute SQL Statement (I have also tried with "Single Row" and above mentioned Result Set Mapping:</p>
  
  <p><a href="https://i.stack.imgur.com/UqhzF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UqhzF.png" alt="enter image description here"></a></p>