jdorn / sql-formatter

A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.
http://jdorn.github.com/sql-formatter/
MIT License
3.89k stars 186 forks source link

Better formating for DECLARE, SET and WITH #115

Closed buutqn closed 11 months ago

buutqn commented 1 year ago

Prevent this outcome: DECLARE @date_today DATE; SET @date_today = '2022-12-12'; DECLARE @date_weekago DATE; SET @date_weekago = '2022-12-05'; WITH duplicate AS (

With this outcome: DECLARE @date_today DATE; SET @date_today = '2022-12-12'; DECLARE @date_weekago DATE; SET @date_weekago = '2022-12-05'; WITH duplicate AS (

My DECLARE SET order is like this due dynamic content being added to the query.

Maybe this doesn't suit all cases, such as multiple set at same line, but WITH and DECLARE at new line seems a must to me

I also added @andig CROSS JOIN