formatting T-SQL

  • Jeff Moden wrote:

    While it's not my job to judge, I do "follow" you on these forums for a reason... you're posts over the last more than a decade have always been helpful and you've always been thoughtful in your responses. You, sir, actually are an "Exceptional DBA" (and exceptional person) and I appreciate every one of your posts.

    Thanks Jeff that means a lot coming from you

    I feel really humble 🙂

    • This reply was modified 4 years, 10 months ago by  David Burrows.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Eirikur Eiriksson wrote:

    I generally use the SQLinForm plugin for Notepad++, works fine for large code sets and most SQL flavors. 😎  

    With some settings changes, that actually does a fairly good job with the "River Format" is spoke of.

    You've got to be damned careful with such formatters, though... here's a snippet of the code I tried on the formatter.  Note the <<Cmd>> notations...

     SELECT REPLACE(REPLACE('
    PRINT "<<Cmd>>";
    EXEC ("<<Cmd>>");
    GO'
    ,'"','''')
    ,'<<Cmd>>',CMD)
    FROM cteCmd
    ORDER BY [Rows]
    ;

    While the formatter does give a warning about carriage returns in some of the comments, it provides absolutely no warning of what it did in the strings.  Here's what it did to that snippet of code, which seriously breaks the code.  Why in the hell would they change a string literal?

       SELECT REPLACE(REPLACE('
    PRINT "<>";
    EXEC ("<>");
    GO' ,'"','''') ,'<>',CMD)
    FROM cteCmd
    ORDER BY [Rows]
    ;

     

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

  • Hmmph... additionally, the "Free" online version is limited to 100 lines of code.  The non-free versions aren't expensive but, considering the bug I found above, I wouldn't spend a nickle on it.  A lot of formatters fall into the same category.

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

Viewing 3 posts - 46 through 47 (of 47 total)

You must be logged in to reply to this topic. Login to reply