• Not sure if I got a bad version of the script, but it doesn't work right - infinitely loops. The problem is line 76; it assumes every chunk to be written is 4000 characters long. So when it checks the last character on anything less than 4000 characters, the full length of the string is never realized.

    I added this and it seems to be working fine now:

    IF LEN(@Chunk) = 4000 And RIGHT(@Chunk,1)...