Urgent help - foreach loop container

  • My case is very simple but I can't resolve the issue using SQL Server 2008R2 BIDS.

    I need to select out a list of managers from a table. Then use foreach loop container to loop through this list and feed to a stored procedure which takes 3 parameters (manager_name, date, interval) to generate a table, say saleperson's performance records under each manager.

    I used execute SQL task to get the list of managers first. The variables are: FullResultSet (data type is object), RepDate (Date), ManagerID (nvarchar). I tried both single and full result set. None worked.

    Next is the foreach loop. Use ADO enumerator, FullResultSet as source variable. Variable mapping both RepDate and ManagerID (with the correct order).

    Inside the container, I use execute SQL task to execute the stored procedure as myStoreProcedure ?,?,?. Parameters mapped as RepDate, ManagerID and Interval (this is in variable list with a default value).

    Issue: The foreach container looped the right number of times. However, the stored procedure never got executed. I didn't get any error message. So I don't know what went wrong? The project is due first thing tomorrow morning. If anybody could help, I'd much appreciated.

  • It sounds to me like you're using the wrong tool.

    Are you using an "Parent/Child" table to drive all of this?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Well, these tables are in Data warehouse. They are not really linked via foreign keys.

    Thanks for your reply. What else would you recommend me to use?

  • My case is almost exactly like this one:

    http://www.sqlservercentral.com/Forums/Topic631921-148-1.aspx

    Wish I have a way to know how this person resolve the issue.

  • whly (5/16/2013)


    Well, these tables are in Data warehouse. They are not really linked via foreign keys.

    Thanks for your reply. What else would you recommend me to use?

    Understood. It sounded like you had a hierarchy going on and wanted to know what type because there are some pretty awesome solutions to report on sales for every node and all levels under each node for hierarchical data that's based on a parent/child relationship.

    You say you execute an SQL Task to get the managers first. Any chance of you posting that to see if I can help? Will likely need other information, as well, but that will be good as a starting point.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

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