Great Script. I however see a similiar problem that I am having, and that I can't seem to solve.
When you run this on a big table with output length more than (10030)
the script cuts off, specifically on the @Insert variable, but suspect it would do so on the @sql variable as well. I checked on the web but can't seem to find a solution.
Maybe you have the answer?