Alignment in columns

Discussion of open issues, suggestions and bugs regarding database management and development tools for SQL Server
Post Reply
MB73
Posts: 2
Joined: Tue 17 Mar 2020 07:42

Alignment in columns

Post by MB73 » Fri 24 Apr 2020 15:02

Hi,

Maybe I just have an issue finding the settings to do the formatting the way I like it, since there are so many things to configure. But I have a few alignment queries.

This code gets formatted OK:

Code: Select all

SELECT b.title,
       a.name
FROM books AS b
JOIN (SELECT name
      FROM authors) AS a ON a.id = b.authorid;
But if the inner select is in the column list, the keywords does not get aligned the same way:

Code: Select all

SELECT b.title,
       name = (SELECT name
          FROM authors a
          WHERE a.id = b.authorid)
FROM books AS b;
So I want the inner FROM and WHERE to be aligned with the inner SELECT.


The second thing I have not found is alignment of join conditions. I want it to be something similar to this:

Code: Select all

SELECT b.title,
       authors.name
FROM books AS b
JOIN authors AS a   ON a.id           = b.authorid
                   AND a.istranslator = 1
JOIN mediatype AS t ON t.media        = b.media;
But I don't manage to align neither the ON / AND or the operators.

Code: Select all

SELECT b.title,
       authors.name
FROM books AS b
JOIN authors AS a ON a.id = b.authorid
         AND a.istranslator = 1
JOIN mediatype AS t ON t.media = b.media;
I can format several things using "table view" but I cannot find it for the join clauses.

It would be much appreciated if this can be done.

alexa

Re: Alignment in columns

Post by alexa » Fri 24 Apr 2020 16:04

You could try the 'Subquery -> Use same formatting as in SELECT', 'SELECT -> FROM -> JOINs -> Line break before ON', 'SELECT -> FROM -> JOINs -> Indent ON keyword' options in the Edit Formatting Profile window.

MB73
Posts: 2
Joined: Tue 17 Mar 2020 07:42

Re: Alignment in columns

Post by MB73 » Mon 27 Apr 2020 06:53

Thank you for your reply, Alexa.

The "'Subquery -> Use same formatting as in SELECT" I already have checked. But it seems like that only takes effect on other formatting but not the "base indention" so to say,

You can see in this code:

Code: Select all

SELECT b.title,
       authors.name,
       city = (SELECT TOP 1 a2.city
       FROM Person.Address AS a2
       WHERE e.rowguid = a2.rowguid
       AND a2.AddressLine1 IS NOT NULL)
FROM books AS b
JOIN authors AS a
   ON a.id = b.authorid
   AND a.istranslator = 1
JOIN (SELECT TOP 1 a2.city
FROM Person.Address AS a2
WHERE e.rowguid = a2.rowguid
AND a2.AddressLine1 IS NOT NULL) AS c
   ON c.city = a.city;
With the other updated settings I get the join conditions aligned, but on a new line. I would like to have them aligned the same way but starting on the same line as the table. Is that possible?

alexa

Re: Alignment in columns

Post by alexa » Tue 28 Apr 2020 08:54

The "'Subquery -> Use same formatting as in SELECT" I already have checked. But it seems like that only takes effect on other formatting but not the "base indention" so to say,
There is no an option for this. Though, you could try the following:
Image
With the other updated settings I get the join conditions aligned, but on a new line. I would like to have them aligned the same way but starting on the same line as the table. Is that possible?
There is no such a possibility in dbForge.

Post Reply