Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Manipulating SSIS variables in script task Expand / Collapse
Author
Message
Posted Thursday, February 14, 2008 11:53 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 16, 2011 1:47 AM
Points: 4, Visits: 8
I have a SSIS package with a script task which I would like to calculate the sum of two int32 variables(say "a" and "b", package level var) and store in variable "c". I'm not familiar with VB/.NET and I follow some books' example and wrote the following code:
-------
If ((Dts.Variables.Contains("a") = True) And (Dts.Variables.Contains("b") = True)) Then

Dts.Variables("c").Value = Dts.Variables("a").Value + Dts.Variables("b").Value

End If
-------
The IDE told me that "Option Strict On prohibits operands of type Object for operator '+'". I don't know also how to set the property of a variable to be readable/writable. Could someone tell me what should I amend to make the script work? Thank you!
Post #456167
Posted Friday, February 15, 2008 5:27 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 12, 2013 8:44 AM
Points: 1,073, Visits: 6,334
The variables would added to the ReadWriteVariables option which is on the same tab where you clicked on Design Script... of the Script Task.

Post #456260
Posted Friday, February 15, 2008 10:19 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 16, 2011 1:47 AM
Points: 4, Visits: 8
Thanks. I think I've already added those variables to the properties (using the format of "User::a", "User::b", etc, w/o quote), is it right? However, it still shows that error message. Would you mind to teach me the necessary steps to make it work? Or point out the steps that maybe missing? Thank you!
Post #456403
Posted Friday, February 15, 2008 1:11 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 12, 2013 8:44 AM
Points: 1,073, Visits: 6,334
First, the variables would be specified as "a,b,c" (without the quotes).

Second, "Option Strict" is a compiler option that's there to help you from introducing logic errors.

For example, set the type for variable "a" to Boolean and set it to true. Set the type for variable "b" to Int32 and set it to 3. Open the script and add "Option Strict Off" at the top and then run the task. With checking off it will not only run but give you an incorrect result.

To make this work, explicitly convert the variables before adding them.

CInt(DTS.Variables("a").value) + CInt(DTS.Variables("b").value)
Post #456502
Posted Monday, February 18, 2008 6:43 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 16, 2011 1:47 AM
Points: 4, Visits: 8
Got it! Thank you! :D
Post #457153
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse