Stored Procedure Return Values and Output Parameters in SSIS

Who is online?  0 guests and 0 members
Home  »  Blogs  »  BillBrannen  »  Stored Procedure Return Values and Output Parameters in SSIS
 
0
/5
Avg: 0/5: (0 votes)

Comments (7)

Scott Huff
Scott Huff said:

Would this technique also work if multiple rows are being returned from the SQL proc, or does there need to be a slight variation?

5/26/2010
 · 
 
by
DaveClark
DaveClark said:

Thanks for the info Bill.  Great examples!  Very helpful tip.

6/20/2010
 · 
 
by
gravelkm
gravelkm said:

Bill,

Great article!  I have a similar scenario that exists in my SSIS package where I'm returning the error number (ERROR_NUMBER() in SQL Server) from a stored procedure (similar to your "RETURN 100;" statement above).  With this error number, if it is not 0, I want to fail the step.  I cannot figure out how to get this to work.  I think I need to use an expression on the "ForceExecutionResult" property.  I've tried things similar to:

@[User::returnVal] == 0 ? 0 : 1

@[User::returnVal] == 0 ? "Success" : "Failure"


Note that @[User::returnVal] is declared as an Int32 variable in SSIS and is specified as having a LONG datatype when being returned from the stored procedure.

Any ideas?

Thanks in advance for your help!

Kevin Gravelle

 

 

7/15/2010
 · 
 
by
SSISinSeattle
SSISinSeattle said:
Another possibility is to place two conditional precedence constraints after the Execute SQL task: One constraint for the "Success" path, and one for the "Failure" path. 1. Connect the Execute SQL task with a precedence constraint (green arrow connector) to the next task on the "Success" path. 2. Double-click the constraint. 3. Select Evaluation operation: Expression AND Constraint; Value: Success; Expression: @[User::returnVal]==0. Test. 4. Connect the Execute SQL task with a precedence constraint (green arrow connector) to the next task on the "Failure" path. 5. Double-click the constraint. 6. Select Evaluation operation: Expression OR Constraint; Value: Failure; Expression: @[User::returnVal]!=0. Test. Click OK and the constraint will turn red. I used this approach when executing five or six stored procedures with Execute SQL tasks. Rather than create a Script Task for each Execute SQL task, I built one Script Task (per Bill’s excellent suggestion) and mapped each Execute SQL task's Failure constraint to the Script Task.
11/28/2011
 · 
 
by
BillBrannen
BillBrannen said:

It looks like expressions are evaluated before a task is executed (read this).  Try placing a Script Task right after your Execute SQL Task and enter the following C# code.

if ((int)Dts.Variables["returnVal"].Value == 0)
{
    Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
    Dts.TaskResult = (int)ScriptResults.Failure;
}

The Script Task will fail if the returnVal variable contains any value other than zero.

7/15/2010
 · 
 
by
Ryan
Ryan said:

Just wanted to say thanks! Had already spent way too much time trying to figure this out, but this article was a life saver!

1/6/2011
 · 
 
by
Caralyn
Caralyn said:

Hi Bill

 

Top article, you are a start I was having issues getting an output variable before I red this article!

 

Thanks again.

 

Caralyn

6/13/2011
 · 
 
by
g3
g3 said:
Thanks much mate, it really saved my day!
9/26/2011
 · 
 
by
  • Name:*
  • Email:*
  • Website:
Type the characters you see in the image: *
Blogs RSS Feed

BillBrannen's latest blog posts

Blogs RSS Feed

Latest community blog posts