Getting ID form loop - SSIS

  • I have a package,where it has for each loop.it will load each state information ( eg - FL,CA etc)
    - In the loop the first step is creating the conenction with encrypt and decrypt tool once succeded next step is  it will insert a record in load table with ID here the result set is ID based on paramters from first component the second component result set will give the ID. when we insert a record for first state.

    Created a variable at package level - ID as Int32.

    Now I need this ID in stored procedure which is outside of loop. How can i get first id from the package?

  • Create a variable to store the value and then pass it?

  • Already created the variable and assigning into result set

    But my question is it loops 13 times..to bring all states information how to track the first state id into that variable?

    By default it will be last state id in the variable when the loop ends right? But i am looking to capture the very first id.

  • mcfarlandparkway - Thursday, February 9, 2017 5:41 AM

    Already created the variable and assigning into result set

    But my question is it loops 13 times..to bring all states information how to track the first state id into that variable?

    By default it will be last state id in the variable when the loop ends right? But i am looking to capture the very first id.

    Variables don't get 'assigned into result sets', so I'm not sure what you mean by that.

    Create another variable and use an expression to assign its value from the existing variable on the first iteration only.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Any syntax for the expression, Not sure how to write the code in expression.

    Can I get an example of the code.

  • mcfarlandparkway - Thursday, February 9, 2017 6:42 AM

    Any syntax for the expression, Not sure how to write the code in expression.

    Can I get an example of the code.

    This is really not that advanced. Here is some pseudo code, please try implementing it and post back with any questions.

    If (LoopCounter == 1)
     Variable2 = LoopVariable

    Obviously, you need to define and increment the LoopCounter variable in your loop to make this work.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • What is this variable 2 and loop variable?

    Variable2 = LoopVariable    

    do we need to define these two at package level? or variable 2 is existing variable which I already have that are storing all the id's ?

Viewing 7 posts - 1 through 6 (of 6 total)

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