SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
SQL Formatting: Left justifying joins

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
SQL Formatting: Left justifying joins
Author Message
mksql



Joined: 29 Dec 2006
Posts: 19
Country: United States

Post SQL Formatting: Left justifying joins Reply with quote
I am attempting to create a formatting pattern for SELECTs that indents join terms on their own lines, with each JOIN keyword left justified:

Code:

SELECT col1,
    col2,
FROM table1 t1
INNER JOIN table2 t2 on t1.id = t2.id
    AND t2.cdate > GETDATE()
LEFT OUTER JOIN table3 t3 on t3.id = t2.id


However the second join in this example follows the indent of the previous line:

Code:

SELECT col1,
       col2,
       
FROM table1 t1
INNER JOIN table2 t2 ON t1.id = t2.id
      AND t2.a > 10
      LEFT OUTER JOIN table3 t3 ON t3.id = t2.id


My format tempate is below. What is incorrect in the template?:

Code:

SELECT ... AS ...,
       ... = ...,
       ... (..., ...)
FROM ... AS ...,
    ... JOIN ... ON ... = ...
      AND ...,
   (...)
WHERE  ... = ...
  AND  ...
   OR  (...)
GROUP BY
       ...,
       (...)
HAVING ...,
       (...)
ORDER BY
       ...,
       (...)

Thu Oct 04, 2007 10:36 am View user's profile Send private message Yahoo Messenger
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6642

Post Reply with quote
Try this

Code:
SELECT ... AS ...,
       ... = ...,
       ... (..., ...)
FROM ... AS ...
JOIN ... ON ... = ...
      AND ...
WHERE  ... = ...
      AND  ...
      OR  (...)
GROUP BY
       ...,
       (...)
HAVING ...,
       (...)
ORDER BY
       ...,
       (...)

Thu Oct 04, 2007 3:25 pm