0

I have a stored procedure which splits a file name (which looks like Name_Date_Number) into 3 different variables. This gets split into Name, Date and Number. I am trying to trigger an Execute SQL Task in SSIS and capture this in three variables.

Details of procedure:

  • Name: FileSplit

This is the procedure's signature:

Create PROC FILESPLIT
AS  BEGIN

 (@FILENAME VARCHAR(20),@Name VARCHAR(10),@Date VARHCHAR(10),@Number int)END

Finally block:

Print @Name 
Print @Date        
Print @Number

SSIS: Execute SQL TASK:

  • SQL: EXEC FileSplit ?,1,1,1

  • Parameter variable: @FileName Direction: Input

Result set:

 @Name 
 @Date        
 @Number  

Problem:

Can anyone please help me to find out why I am not able to capture the above result in the variables? I need to use these variables in further down the packages for various other function.

EDIT:

Below is the stored procedure signature:

Create PROC FILESPLIT       
 (@FILENAME VARCHAR(20),@Name VARCHAR(10) OUT,@Date VARHCHAR(10) OUT,@Number int OUT)
As BEGIN
.......
END

1 Answer 1

1

Printing does not return a result set. It's handled in a separate channel.

Your options are OUTPUT parameters in your stored procedure or a proper resultset.

-- this is your final line
SELECT @Name AS [Name], @Date AS [Date], @Number AS [Number];

Edit

As noted, you have two choices. You can return a result set or you can use output parameters.

CREATE PROCEDURE dbo.OutParameters(@FILENAME VARCHAR(20),@Name VARCHAR(10) OUT,@Date VARCHAR(10) OUT,@Number int OUT)
AS
BEGIN
    SET NOCOUNT ON;
    SELECT 
        @Name = 'Hello' 
    ,   @Date = 'Really?'
    ,   @Number = 1;
END
GO
CREATE PROCEDURE dbo.ResultSet(@FILENAME VARCHAR(20))
AS
BEGIN
    SET NOCOUNT ON;
    SELECT 
        [Name] = 'Hello'
    ,   [Date] = 'Really?'
    ,   [Number] = 1;
END
GO

Great, now I have procedures that do things. Time to wire them up

SQL Resultset

This Execute SQL Task calls the stored procedure as indicated below.

EXECUTE dbo.ResultSet ?

I have changed the ResultSet from None to SingleRow.

In my Parameters, I have mapped my input, @[User::FileName] as input parameters

In my ResultSet tab, I have assigned my RS namespaced variables to ordinal positions 0, 1, and 2.

SQL Out

This Execute SQL Task calls the stored procedure as indicated

EXECUTE dbo.OutParameters ?, ? OUT, ? OUT, ? OUT;

My ResultSet remains at None

In my Parameters, I have mapped my input, @[User::FileName] as input parameters and the three OUT namespaced parameters as such.

proof

Recreate my demo

Install BIDS Helper It's free and it's the only way to make your experience, pre 2012, not revolting.

Once installed, open an Integration Services project and right click on the project. "Add New Biml File". Biml, Business Intelligence Markup Language, is an XML dialect that describes SSIS and SSAS concepts. We're going to have Bids Helper use our Biml to generate an SSIS package.

You will need to adjust the ConnectionString in OleDbConnection to match your Data Source and Initial Catalog and possibly the Provider as well

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Connections>
        <OleDbConnection ConnectionString="Provider=SQLNCLI11;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=tempdb" Name="CM_OLE" />
    </Connections>
    <Packages>
        <Package Name="so_24872805" ConstraintMode="Linear">
            <Variables>
                <Variable Name="FileName" DataType="String">Hello.txt</Variable>
                <Variable Namespace="RS" Name="Date" DataType="String"></Variable>
                <Variable Namespace="RS" Name="Name" DataType="String"></Variable>
                <Variable Namespace="RS" Name="Number" DataType="Int32">0</Variable>
                <Variable Namespace="OUT" Name="Date" DataType="String"></Variable>
                <Variable Namespace="OUT" Name="Name" DataType="String"></Variable>
                <Variable Namespace="OUT" Name="Number" DataType="Int32">0</Variable>
            </Variables>
            <Tasks>
                <ExecuteSQL
                    Name="SQL Resultset"
                    ConnectionName="CM_OLE"
                    ResultSet="SingleRow"
                >
                    <DirectInput>EXECUTE dbo.ResultSet ? </DirectInput>
                    <Parameters>
                        <Parameter DataType="AnsiString" Length="20" Name="0" VariableName="User.FileName" DataTypeCodeOverride="129" />
                    </Parameters>
                    <Results>
                        <Result Name="0" VariableName="RS.Name" />
                        <Result Name="1" VariableName="RS.Date" />
                        <Result Name="2" VariableName="RS.Number" />
                    </Results>
                </ExecuteSQL>
                <ExecuteSQL
                    Name="SQL Out"
                    ConnectionName="CM_OLE"
                    ResultSet="None"
                >
                    <DirectInput>EXECUTE dbo.OutParameters ?, ? OUT, ? OUT, ? OUT; </DirectInput>
                    <Parameters>
                        <Parameter DataType="AnsiString" Length="20" Name="0" VariableName="User.FileName" DataTypeCodeOverride="129" />
                        <Parameter DataType="AnsiString" Length="10" Name="1" VariableName="OUT.Name" Direction="Output" DataTypeCodeOverride="129" />
                        <Parameter DataType="AnsiString" Length="10" Name="2" VariableName="OUT.Date" Direction="Output" DataTypeCodeOverride="129" />
                        <Parameter DataType="Int32" Name="3" VariableName="OUT.Number" Direction="Output" />
                    </Parameters>
                </ExecuteSQL>

            </Tasks>
        </Package>
    </Packages>
</Biml>
3
  • Hey, thank you soo much for the answer. I did out the above as the final line in the stored Procedure. But still not able to read the above three into Variables. Error that I am getting is "[Execute SQL Task] Error: There is an invalid number of result bindings returned for the ResultSetType: "ResultSetType_SingleRow". "
    – snp.it
    Jul 21, 2014 at 20:55
  • So this is what I have as in execute SQL task "Exec FILENAME_SPLIT ?,?,?,?" . In parameter mapping the first one is input parameter and rest I have it marked as Output direction.
    – snp.it
    Jul 21, 2014 at 20:57
  • How do I call the output of the procedure in SSIS?
    – snp.it
    Jul 22, 2014 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.