How to keep short IIF functions on one line in SELECT clauses?

14 Posts
2 Users
1 Reactions
3,503 Views
Guido
Posts: 295
Admin
(@admin)
Member
Joined: 5 years ago

Hi @kmpel,

please uncheck these 2 options to make it more compact

grafik

The current logic for indention for functions is to indent on the open bracket level. As the IIF functions move to the right in your statement, the indentions are also moving to the right. The formatting is therefore working correctly. but it does not mean when something works correctly that it is nice. Therefore I am thinking about special formatting / indention rules for iif functions. I am open for any suggestion. One idea of mine was to put a line-break before the "+".

REgards

Guido


Reply
Posts: 13
Topic starter
(@kmpel)
Member
Joined: 7 months ago

Hi Guido, thank you for working on this. I check it out. I think working out when to align operators, such as the plus sign (+), is a tough logic problem.  In my opinion, the way is to 1) use the equal sign as an assignment operator only to align; the equal sign as a comparator to never align. 2) Keep the function with its rounded brackets together. 3) Leave the developer manually format to represent the logic. I think it's better to leave the developer to define the structure of the logic rather than guessing his/her way of thinking and force it into some general structure 😉 

I think one good option is what you already have, FORMAT_ON/OFF. I'd also suggest a COLFORMAT_OFF in this case, one line for the select clause whihc is quite important in SQL. Please see my sample below.

 

SELECT
    LocalAmount       = @AmountOnAccount

    --Still strange formatting; difficult to understand the logic
   ,DescriptionMain = IIF(ISNULL(@Description1, '')                      != '', @Description1
                         ,'')           + IIF(ISNULL(@Description2, '')  != '',' | '  + @Description2
                                   ,'') + IIF(ISNULL (@Description3 ,'') != '', ' | ' + @Description3
                                             ,'')
    --FORMAT_OFF
   ,DescriptionMainFormanOff    =   IIF(ISNULL(@Description1, '') != '', @Description1, '')  
                                  + IIF(ISNULL(@Description2, '') != '',' | ' + @Description2 , '') 
                                  + IIF(ISNULL(@Description3 ,'') != '',' | ' + @Description3 ,'')
    --FORMAT_ON



/*
--Suggested behaviour: when row is followed by a comment do not format this column calculation
   ,DescriptionMainRowComment   =   IIF(ISNULL(@Description1, '') != '', @Description1, '')          --COLFORMAT_OFF
                                  + IIF(ISNULL(@Description2, '') != '',' | ' + @Description2 , '') 
                                  + IIF(ISNULL(@Description3 ,'') != '',' | ' + @Description3 ,'')
*/

Reply
Guido
Posts: 295
Admin
(@admin)
Member
Joined: 5 years ago

Hi @kmpel, very interesting idea! Will check how to include this option

Already now, you can add --FORMAT_OFF and --FORMAT_ON at line-end, and it will format like this

grafik

Reply
Page 3 / 3
Share: