I forgot to reset the @final_sql variable so it was continually adding on. Down where you close the cursor put in Set @final_sql = ''
. You may also want to check the length of the variable and when it gets to 8000 kick out as well. Something like Len(@final_sql + @sql) < 8000 added to the @@FETCH_STATUS.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question