Executing stored procedure from SSIS

  • I am new to SSIS. I am calling a stored procedure from Execute SQL Task with the syntax:

    EXEC usp_AddUpdate ?, ?, ? OUTPUT, ? OUTPUT

    The stored procedure has 4 parameters, i.e.  2 input & 2 output parameters

           @QuaterID                  bigint=null

    ,@UserName                 nvarchar(256)=null

    ,@Success                  bit output

    ,@OutMessage                varchar(512) output

    In SSIS, I created new variables in Parameter Mapping tab of the Execute SQL Task. It is as follows:

    Variable name     Direction    Data Type     Param. Name   Param. Size

    User::QuaterID    Input           NUMERIC      0                          -1

    User::UserName  Input           NVARCHAR   1                          -1

    User::Success       Output        BYTE              2                           -1

    User::OutMessage Output     LONG            3                            -1

     

    a)       I just need to know whether it is correct & will it work there?

    b)      Also, should I specify anywhere the Default value NULL of stored procedure Input Parameters.

    Thanks in advance

  • Looks close. You should add the correct param size for the NVARCHAR column.

    Quarter has an 'r' in it.

    I do not understand your question (b). If you plan to call the proc without including certain params, you need specify the NULL defaults in the proc definition. If you will always include the params in your proc calls, don't specify defaults.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Also, the 0, 1, 2 ... parameter naming is valid for OLEDB connections. If you are using an ADO connection, you should include the actual parameter names.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thanks, I am using the OLEDB connection.

    I want to pass the following query resultset value as input parameter value for @QuaterID.

    SELECT QuaterID FROM Nodes WHERE NodeID = (SELECT MAX(NodeID) FROM Nodes)

    For this, I have created a Execute SQL Task with the above query. This task will execute ahead of the task which execute the stored procedure.

    How to set the value return by the query as the value of the input parameter @QuaterID.?

  • 'Quater' ... do you mean 'Quarter', by any chance?

    Not sure I understand: are you trying to set the value of an SSIS package variable to the 'QuaterID' which the above query returns?

    Your query might run faster in this form ... worth a test anyway:

    SELECT TOP (1)
    QuaterID
    FROM Nodes
    ORDER BY NodeID DESC;

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Yes, this query returns a value 4. This value 4 needs to be passed as input parameter value for input parameter @QuaterID.

  • How can it be done? Please explain the steps.

    1. Change the ResultSet property of your ExecSQL task to 'Single Row'
    2. Select the Result Set node of the ExecSQL task and click on Add

      1. Set Result Name to 0 (zero)
      2. Set variable name to the SSIS package variable name (User::...)

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thank You Phil..It worked like charm. Both query tweak & SSIS tip worked great for me.

  • When the above query in the ExecSQL task returns 0 rows, the task is getting failed due to 'Single Row' property.

    What can be done to avoid this error & keep the task running?

  • You need to make sure that your SQL returns a row (and exactly one row), even if there is no underlying data. You could do this with a UNION ALL and an appropriate ORDER BY to ensure that the 'dummy row' is selected only if there is no 'proper' data.

    With ExpandedDataset as (
    select col1, col2
    from table
    union all
    select col1 = -9999, col2 = -1
    )
    select top (1) *
    from ExpandedDataset
    order by col1 desc

    • This reply was modified 4 years, 10 months ago by  Phil Parkin.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thanks for the reply. I changed my above query accordingly i.e. the way you have suggested. I hope it will work.

    With ExpandedDataset as (
    select NodeID, QuaterID
    from Nodes
    union all
    select NodeID = -9999, QuaterID = -1
    )
    select top (1) QuaterID
    from ExpandedDataset
    order by NodeID desc;

    Also, I am am giving the table schema of the table,  Nodes. Please advice me whether using the present datatype used, these columns will hold the value like -9999 &  -1.

    CREATE TABLE [dbo].[Nodes](
    [NodeID] [bigint] NOT NULL,
    [QuaterID] [tinyint] NULL,
    CONSTRAINT [PK_Nodes] PRIMARY KEY CLUSTERED
    (
    [NodeID] ASC
    )
    ) ON [PRIMARY]
    GO
  • Looks good to me ... that should work (assuming you have no values for NodeId which are less than -9999 ... which you should confirm).

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thanks Phil !! Both the columns NodeID & QuarterID are having records starting from 1. Hence it won't be a issue.

  • What if I have a column CreatedBy which is having datatype NVarchar(256) NULL instaed of QuarterID. I have changed my query like the one below. Will it be ok?

    With ExpandedDataset as (
    select NodeID, CreatedBy
    from Nodes
    union all
    select NodeID = -9999, CreatedBy = NULL
    )
    select top (1) CreatedBy
    from ExpandedDataset
    order by NodeID desc;

    • This reply was modified 4 years, 10 months ago by  VSSGeorge.

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic. Login to reply