microsoft / vscode-mssql

Visual Studio Code SQL Server extension.
Other
1.53k stars 456 forks source link

Formatter option for newline between WHERE clauses #1002

Open esetnik opened 6 years ago

esetnik commented 6 years ago

Steps to Reproduce:

  1. Open sql file with select statement like below:

A)

SELECT
            U.FirstName,
            U.LastName

                FROM
                Users U
                WHERE 
                U.FirstName = 'test'
                AND U.LastName = 'test'

B)

SELECT U.FirstName, U.LastName FROM Users U WHERE U.FirstName = 'test' AND U.LastName = 'test'
  1. Run formatter (shift+option+f) and output is:

A)

SELECT
    U.FirstName,
    U.LastName
FROM
    Users U
WHERE 
                U.FirstName = 'test' AND U.LastName = 'test'

B)

SELECT
    U.FirstName,
    U.LastName
FROM
    Users U
WHERE U.FirstName = 'test' AND U.LastName = 'test'

Expected:

  1. The WHERE clause has the same amount of leading padding as the SELECT and FROM clauses.
  2. Each condition is on a newline
    SELECT
    U.FirstName,
    U.LastName
    FROM
    Users U
    WHERE 
    U.FirstName = 'test'
    AND U.LastName = 'test'
  3. Both A) and B) variants above produce the same formatted result

The behavior of various formatters varies, but this is consistent with https://www.freeformatter.com/sql-formatter.html. Without formatting where clauses in this manner complicated sql queries become impossible to read because the WHERE clause is collapsed into a long single line.

kevcunnane commented 6 years ago

Thanks for raising this - it looks like a valid request. We'll see whether it's possible to address this when working on formatter issues in the future (and I'll forward on to some people investigating improved formatting support).

I'm also tagging this as help wanted as it's a good candidate for community contribution.

esetnik commented 6 years ago

Thank you. I don't have time to work on a solution at the moment, but I appreciate the community effort.

grupoGovanBI-nluque commented 5 months ago

Hi, is this issue solved ? i'm facing the same need in WHERE CLASUES, difficult to read. I use this formatter every day at work. Thanking in advance.