Author |
Message |
Daveii
Joined: 10 Dec 2008 Posts: 22 Country: United States |
|
Format - Indent and Comments |
|
Trying to get the following 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:
 |
 |
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:
 |
 |
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:
 |
 |
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 |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
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 |
|
 |
Daveii
Joined: 10 Dec 2008 Posts: 22 Country: United States |
|
|
|
Excellent suggestion. Please see the attached image.
[/img]
|
|
Wed Dec 10, 2008 12:54 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
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 |
|
 |
Daveii
Joined: 10 Dec 2008 Posts: 22 Country: United States |
|
|
|
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 |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
I'm still playing with this. It seems that the formatter produces the required result when comments aren't between lines
 |
 |
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 |
|
 |
Daveii
Joined: 10 Dec 2008 Posts: 22 Country: United States |
|
|
|
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 |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
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 |
|
 |
Daveii
Joined: 10 Dec 2008 Posts: 22 Country: United States |
|
|
|
Not sure why...but...changing the template from "inner join" to "join" fixed the issue.
|
|
Sun Dec 14, 2008 1:48 am |
|
 |
|