 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
drventure
Joined: 15 Apr 2011 Posts: 2 Country: United States |
|
Formatting a single line IF statement |
|
Hi
I've been working through trying to get a format style set for single line IF statements in SQL server.
I know I'm setting the right option because the code formatting does reflect my changes if I change the normal IF item.
But, what I'd like is for single line IF statements to be left as single line, instead of broken to a second line
For instance
IF 1=0 exec MyStoredProc
When I format the above, it turns into
IF 1=0
Exec MyStoredProc
I'd prefer SQLA to just leave that form of IF alone, BUT go ahead and reformat multiline IF statements that have a BEGIN END
Is that possible?
Thanks
|
|
Fri Apr 15, 2011 12:50 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
I think in this case you can simply disable IF rule to make it ignore IF lines. BEGIN...END rule will take care of the rest.
But, you may see another problem with misaligned multi-line statements following IF lines and also similar issues with misaligned multi-line statements following ELSE, for example try
I think in this case you can simply disable IF rule to make it ignore IF lines. BEGIN...END rule will take care of the rest.
But, you may see another problem with misaligned multi-line statements following IF lines and also similar issues with misaligned multi-line statements following ELSE, for example try
 |
 |
IF 1 < 2
SELECT 'line1',
'line2'
FROM some_table
WHERE 4 = 4
ELSE
SELECT 'line1',
'line2'
FROM some_other_table
WHERE 0 = 0 |
|
|
Sat Apr 16, 2011 1:56 pm |
|
 |
drventure
Joined: 15 Apr 2011 Posts: 2 Country: United States |
|
|
|
Ah, yes, that works, but for those IF's with a multi line single statement, it messes up the ELSE
So... It sounds like it's not possible to create TWO rules for IF formatting, one if a single line IF is detected, and one for multiline IF's?
|
|
Mon Apr 18, 2011 11:35 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
There is definitely no way to create 2 rules for the same statement. I mean you can enter as many of them as you want, but one will always take precedence over other rules defined for the same statement.
However, if your coding style is consistent you can likely set some set of "alternating" rules. For example, if for a single line IFs you never use BEGIN…END and for multi-line statements after IF or ELSE you always use BEGIN…ELSE, then you can define a new rule for ELSE, which would be as simple as "ELSE …" without quotes
|
|
Mon Apr 18, 2011 10:28 pm |
|
 |
|
|
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
|
|
|