I have an SSIS package that is executing dynamic SQL. The Dynamic SQL will sometimes have result set and sometimes not, but I only want to capture the COUNT, which is the returned value in below script.
(or can I use C# Script task to accomplish this?), I know I can loop through record sets in C#, but I wont always have 2, is there way to tell difference in result sets by name or something, or only by index of array in resultset[x]?
-- These are passed values in SSIS as paramaters
DECLARE @VariablePassedForSelect AS VARCHAR(50) = ?
DECLARE @ScriptToExecute NVARCHAR(MAX) = ?
-- putting return value count from dynamic script into variable
DECLARE @ReturnRowsEffectedA INT
-- this MAY (or may not) return a result set as dynaic code
exec sp_executesql @ScriptToExecute, N'@VariablePassedForSelect BIGINT, @ReturnRowsEffected INT OUTPUT', @VariablePassedForSelect = @VariablePassedForSelect, @ReturnRowsEffected = @ReturnRowsEffectedA OUTPUT
-- now select results for returning,this is only value I want
SELECT @ReturnRowsEffectedA AS RowCountR
All this works fine in SQL and returns the result set from the dynamic SQL and the count, but I only want the COUNT returned into a variable in SSIS.
If I use result set, I get error for single row (because of the dynamic sql can return results and count).
Three are reasons I am doing it this way and not using SP's or other means, but those details are not required for my question.
How can I only capture just the value for @ReturnRowsEffectedA?