user967845
user967845

Reputation: 11

SISS Variables -

I have created user defined SSIS variables at the package level.

Example: Here are the varibales

v1 = 10

v2 = 20

v3

The result should be V3 = V1 +V2 Where should i give this expression in the control flow and will i get the result

Please help

Thanks

Upvotes: 1

Views: 299

Answers (2)

billinkc
billinkc

Reputation: 61201

Am I missing something or is there a reason an expression won't suffice?

Given variables defined as described above

Variables window

Set "Evaluate as Expression" to True on the variable v3 and for the Expression, use @[User::v1] + @[User::v2] (or click the ellipses and build the expression with the WYSIWYG editor)

Properties window

If you notice the pink corner of v3, that is due to me running an add-in called BIDSHelper which can assist in your SSIS development tasks but in no way affects the workings of my solution.

Upvotes: 3

thursdaysgeek
thursdaysgeek

Reputation: 7926

You can manipulate variables within a Script Component. If you're using SQL-Server 2005 you get to use VB.Net, if you're using 2008, you have the choice of that or C#.net.

Here are some (VB.net) examples of code I've used to get variables (strings in my case), manipulate them, and send them back to the variable storage area:

Dim logFilename As String
Dim logFilePath As String

' create filename
logFilePath = Dts.Variables("LogFilePath").Value.ToString()
curDate = Now().ToString("yyyyMMdd")
logFilename = "test-" & curDate & ".Log"
Dts.Variables("LogFileName").Value = logFilename

To do the same with your numbers, in the guts of the Script Component (I'm a bit rusty with VB)

Dim v1 as Int
Dim v2 as Int
Dim v3 as Int

// get your variables from the package 
v1 = Dts.Variables("v1").Value
v2 = Dts.Varuables("V2").Value
v3 = v1 + v2
// set your result back to the package
Dts.Variables ("v3").Value = v3

Upvotes: 1

Related Questions