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

Format issues #230

Open MeboGit opened 5 years ago

MeboGit commented 5 years ago

I use the batch version within DBeaver/MariaDB.

About the following formatted sql I have 3 issues/questions:

  1. The formatter generates a line feed before and after "union all". How can I avoid this?
  2. Is it possible to have "create or replace" in one line?
  3. A possibility to filter the backticks (`) would be very cool. Or is this possible somehow?
create
  or REPLACE view `v_auftrag` as
select 'Umzug' as `typ`,
  `x`.`datum` as `datum`,
  `x`.`id` as `id`,
  `x`.`team_user_id` as `team_user_id`,
  `x`.`datum_von` as `datum_von`,
  ifnull(`x`.`datum_bis`, `x`.`datum_von`) as `datum_bis`
from `umzug` `x`
having (
    `x`.`id` = (
      select max(`umzug`.`id`)
      from `umzug`
      where (
          (`umzug`.`datum_von` is not null)
          and (`umzug`.`datum_von` = `x`.`datum_von`)
          and (`umzug`.`team_user_id` = `x`.`team_user_id`)
          )
      )
    )

union all

select 'Entsorgung' as `typ`,
  `x`.`datum` as `datum`,
  `x`.`id` as `id`,
  `x`.`team_user_id` as `team_user_id`,
  `x`.`datum_von` as `datum_von`,
  ifnull(`x`.`datum_bis`, `x`.`datum_von`) as `datum_bis`
from `entsorgung` `x`
where (
    (
      not (
        exists (
          select 1
          from `umzug`
          where (
              (`umzug`.`datum_von` is not null)
              and (ifnull(`umzug`.`team_user_id`, 0) = ifnull(`x`.`team_user_id`, 0))
              and (`umzug`.`datum_von` = `x`.`datum_von`)
              )
          )
        )
      )
    and (`x`.`datum_von` is not null)
    )
order by 2 desc,
  3 desc