• The was (re)posted on SQLServerCentral and delivered to my inbox on the very day that I needed to examine why a 8k+ VARCHAR(MAX) dynamic SQL string was not executing the last few commands in the string. I had problems making Jeff's code work correctly using 8000 characters. When I reduced the 8000 to 1000, the code worked perfectly.

    Turns out that my copy of SSMS was set to display a maximum of 1024 characters in each column on "Results to Text" output. I know I've never changed it, and no-one else has access to this box. Anyway, changing the value to 8192 (the maximum that SSMS 2008R2 allows) STILL didn't work, until I closed the tab containing the test script and reopened it. At that point, Jeff's original 8k value worked.

    Jeff, perhaps the original posting should have a postscript added that discusses this situation. Anyway, thanks for sharing your insight with us huddled masses! <g>