TaoK / PoorMansTSqlFormatter

A small free .Net and JS library (with demo UI, command-line bulk formatter, SSMS/VS add-in, notepad++ plugin, winmerge plugin, and demo webpage) for reformatting and coloring T-SQL code to the user's preferences.
http://www.architectshack.com/PoorMansTSqlFormatter.ashx
GNU Affero General Public License v3.0
969 stars 268 forks source link

Poor formatting for SQL functions #195

Open klahnakoski opened 6 years ago

klahnakoski commented 6 years ago

This following formatted case statement is difficult to read. May I suggest that function parameters have their own lines when the parameter list gets "too long", and all the CASE clauses align vertically.

Instead of outputting

(
        CASE 
            WHEN (("v.$string") IS NULL)
                OR (("v.$string") = '')
                THEN NULL
            ELSE SUBSTR("v.$string", CASE 
                        WHEN ((1) IS NULL)
                            OR ((max(0, min(LENGTH("v.$string"), (LENGTH("v.$string")) - (4)))) IS NULL)
                            THEN NULL
                        ELSE (1) + (max(0, min(LENGTH("v.$string"), (LENGTH("v.$string")) - (4))))
                        END, (LENGTH("v.$string")) - (max(0, min(LENGTH("v.$string"), (LENGTH("v.$string")) - (4)))))
            END
        ) = ('test')

ensure multi-line CASE statements have the clauses aligned,

(
    CASE 
    WHEN (("v.$string") IS NULL) OR (("v.$string") = '')
    THEN NULL
    ELSE 
        SUBSTR(
            "v.$string"
            ,CASE 
            WHEN ((1) IS NULL) OR ((max(0, min(LENGTH("v.$string"), (LENGTH("v.$string")) - (4)))) IS NULL)
            THEN NULL
            ELSE (1) + (max(0, min(LENGTH("v.$string"), (LENGTH("v.$string")) - (4))))
            END
            ,(LENGTH("v.$string")) - (max(0, min(LENGTH("v.$string"), (LENGTH("v.$string")) - (4))))
        )
    END
) = ('test') 

thank you