• Please take a step back and take a good look at your requirements.

    Why do you want to insert the data using seperate insert statements? The performance will be a lot better if you take a set-based approach. So alter the query to not return insert statements, but rather return a complete set of data that needs to be inserted. Then you can use this result set to be inserted in the destination table at once.

    INSERT INTO {your_table}

    SELECT {column list}

    FROM {rest of your query}

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **