Page 1 of 1

Alignment in columns

Posted: Fri 24 Apr 2020 15:02
by MB73
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.

Re: Alignment in columns

Posted: Fri 24 Apr 2020 16:04
by alexa
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.

Re: Alignment in columns

Posted: Mon 27 Apr 2020 06:53
by MB73
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?

Re: Alignment in columns

Posted: Tue 28 Apr 2020 08:54
by 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,
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.