• KEVHOUSTON740 (8/20/2012)


    The data does exist. I am looping through the data because there may be 1 or 20 child data sets, per parent, and i need to have the same number of rows in the history table. When I didn't loop through the child table I only saw one row being added to the child history table.

    OK well now you have me confused. In your first post you said your looping was working but you didn't get data. Now you are saying the looping isn't working.

    You really don't need a loop for this at all. There is no need for a loop. Loops in t-sql are terrible for performance and are more prone to coding errors because they are more complex than a simple select.

    If the version I posted above still doesn't work you are going to have to provide some more details. We would need to have ddl (create table scripts), sample data (insert statements) and a clear explanation of desired output. Take a look at the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/