• 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.