SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Formatting a single line IF statement

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Formatting a single line IF statement
Author Message
drventure



Joined: 15 Apr 2011
Posts: 2
Country: United States

Post Formatting a single line IF statement Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
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

Code:
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 View user's profile Send private message
drventure



Joined: 15 Apr 2011
Posts: 2
Country: United States

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


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
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 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.