• opc.three (6/29/2013)


    If the goal is only to see the data in the variable for purposes of debugging then here is an alternate method which I find works quite well. I prefer it over the tally table method only because it requires less thought to recall from memory (I'm lazy too). An added benefit is that it let's me see the uninterrupted text with all formatting left intact:

    -- test code from article goes here...

    SELECT @LongString AS [processing-instruction(LongString)]

    FOR XML PATH(''), TYPE;

    SELECT @NLongString AS [processing-instruction(NLongString)]

    FOR XML PATH(''), TYPE;

    Credit: I picked up this technique from reading the source code for Adam Machanic's sp_WhoIsActive. He employs this technique to deliver the sql-text for a given session which can exceed 8000 bytes.

    Edit: add , TYPE to FOR XML clause.

    Oh, now THAT's bloody clever and super easy to remember. It's soooooooo simple! Works in 2k5, as well. Just click on the resulting XML in the grid and a window opens up with the whole shootin' match right there. I just tested it on a 26KB NVARCHAR (13K characters) and it works great.

    For anyone else that reads this, the AS [processing-instruction(xxx)] is super important for de-entitization. The "xxx" can be anyword but I use "SQL" there for consistancy.

    Outstanding tip, Orlando. Thanks for posting it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)