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: 7833

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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7833

Post Reply with quote
By the way, version 3 will support multiple formatting styles.
Thu Oct 04, 2007 3:33 pm View user's profile Send private message
mksql



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

Post Reply with quote
That template gives me this output:

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

Thu Oct 04, 2007 6:11 pm View user's profile Send private message Yahoo Messenger
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.