• timothyawiseman (2/1/2011)


    I have run into this problem off and on, and once even wrote a solution to it ( http://www.sqlservercentral.com/scripts/Print/63240/[/url] ). After struggling with it myself a few times, I am in awe of the elegance of your solution. It is very clean and effecient and easy to understand.

    One challenge that I think remains in your technique is that the output is in the form of a select statement rather than a print. While you can certain output to text as you mentioned, that can be problematic if your are troubleshooting something and want other output to come out as a grid. Still, an absolutely beautiful piece of code.

    Wow! :blush: I'm humbled, Timothy. Thanks for the very kind words and the awesome feedback.

    I absolutely agree... the grid/text mix is very helpful in troubleshooting and forcing the results to the Messages tab to see a bit of correctly formatted dynamic SQL along with the data it produced works best when the grid/text mix is available.

    --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)