SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Format - Indent and Comments

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Format - Indent and Comments
Author Message
Daveii



Joined: 10 Dec 2008
Posts: 22
Country: United States

Post Format - Indent and Comments Reply with quote
Trying to get the following code:

Code:

select *
from   dbo.table1 ag
--My First Comment
inner  join dbo.table2 cc
on     1 = 1
--My Second Comment
inner join dbo.table3 cn
on     1 = 1


to format as:

Code:

select *

from   dbo.table1           ag

--My First Comment
inner  join dbo.table2      cc
on     1 = 1

--My Second Comment
inner join dbo.table3       cn
on     1 = 1


Instead, I get:

Code:

select *

from   dbo.table1 ag
       --My First Comment
inner  join join dbo.table2 cc
on     1 = 1
       --My Second Comment
       inner join dbo.table3 cn
on     1 = 1



My template is:

Code:

SELECT ... AS ...
      ,... = ...

FROM   ... AS ...
      ,...

...
INNER  JOIN ...
ON     ... = ...
AND    ...

WHERE  ... = ...
AND    ...
OR     ...

GROUP  BY
       ...
      ,...

HAVING ...
      ,...

ORDER  BY
       ...
      ,...


Any ideas will be greatly appreciated!!!
Wed Dec 10, 2008 9:15 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7842

Post Reply with quote
Would you please attach a screenshot demonstrating what you want to get as a result of the formatting? You can use "add image to post" link to do that.

When a web page is displayed in a browser, spaces between words are ignored and collapsed making it hard to understand how keywords should be offset.
Wed Dec 10, 2008 10:45 am View user's profile Send private message
Daveii



Joined: 10 Dec 2008
Posts: 22
Country: United States

Post Reply with quote
Excellent suggestion. Please see the attached image.


[/img]
Wed Dec 10, 2008 12:54 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7842

Post Reply with quote
I'm not sure if empty lines can be added this way in middle of a formatted SQL statement. I will consult with the developers and get back to you on this.
Wed Dec 10, 2008 1:11 pm View user's profile Send private message
Daveii



Joined: 10 Dec 2008
Posts: 22
Country: United States

Post Reply with quote
What about getting a blank line before the second "inner join" and getting it to align to the left? The actual format I received is attached:



Thanks! I look forward to your response regarding getting the comments to align.
Wed Dec 10, 2008 1:20 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7842

Post Reply with quote
I'm still playing with this. It seems that the formatter produces the required result when comments aren't between lines

Code:
SELECT *
FROM   dbo.table1 ag
INNER  JOIN dbo.table2 cc   --My First Comment
ON       1 = 1
INNER JOIN dbo.table3 cn    --My Second Comment
ON       1 = 1



But when comments are between joins, it treats them as part of the expression, moving them along ON and causing side effects.

Basically keywords provide anchors for the formatting pattern. Everything else (non-keywords) is treated as expressions handled and positioned as specified by location of (,,,) placeholders. The formatter doesn't treat comments within formatting pattern as some special elements.
Wed Dec 10, 2008 1:36 pm View user's profile Send private message
Daveii



Joined: 10 Dec 2008
Posts: 22
Country: United States

Post Reply with quote
We must be getting different results. When I remove the comments, the second inner join is not left aligned and I don' t get the desired blank line between the joins.

I seem to recall a place to add keywords. Could a comment be added as a keyword?
Wed Dec 10, 2008 1:54 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7842

Post Reply with quote
I'm running 4.1.8. Which version are you running?

Here is what I found out from developers. Empty lines are ok and will be inserted as specified in the formatting pattern. Comments entered on separate lines within the statement text are not ok. Comments should either be entered before or after the statement or follow non-empty lines. Such in-line comments are treated as part of the SQL code just as all other non-keywords within the statement.

No, comments are not fixed elements and cannot be entered as keywords.
Wed Dec 10, 2008 2:18 pm View user's profile Send private message
Daveii



Joined: 10 Dec 2008
Posts: 22
Country: United States

Post Reply with quote
Not sure why...but...changing the template from "inner join" to "join" fixed the issue.
Sun Dec 14, 2008 1:48 am View user's profile Send private message
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.