Enhancement Proposal: Single-Line Formatting for Simple CASE WHEN Statements in SqlInform

12 Posts
2 Users
0 Reactions
1,354 Views
Posts: 17
Topic starter
(@benjamin-moeller)
Member
Joined: 4 years ago
[#113]

I love how SqlInform allows me to format case when statements.
To make this even better, please specify that simple case when statements are formatted into one line.

Here is an example.

This sql:

select field_1 as my_field, case when field_1 = 'Snowflake' then 'Cloud' when field_2 = 'Oracle' then 'On-Premises' else 'Check' end as group_1,
case when field_1 is null then 'Empty' else field_1 end as test2 from test

 

can be automaticly formattet as:

    SELECT
                  field_1                       AS my_field
            ,
                  CASE
                         WHEN   field_1 = 'Snowflake'
                         THEN   'Cloud'
                         WHEN   field_2 = 'Oracle'
                         THEN   'On-Premises'
                         ELSE   'Check'
                  END                           AS group_1
            ,
                  CASE
                         WHEN   field_1 IS NULL
                         THEN   'Empty'
                         ELSE   field_1
                  END                           AS test2
             FROM test

 

but I would like it to be in this way:

    SELECT
                  field_1                                                                    AS my_field
            ,
                  CASE
                         WHEN   field_1 = 'Snowflake'
                         THEN   'Cloud'
                         WHEN   field_2 = 'Oracle'
                         THEN   'On-Premises'
                         ELSE   'Check'
                  END                                                                        AS group_1
            ,
                  CASE   WHEN   field_1 IS NULL   THEN   'Empty'  ELSE   field_1  END        AS test2
             FROM test

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

Hi @benjamin-moeller, what would be the rule/definition of a "simple" CASE?

Would it be the number of chars? e.g. < 80 chars?

 

Regards

Guido


Reply
Posts: 17
Topic starter
(@benjamin-moeller)
Member
Joined: 4 years ago

Hi Guido

i would prefer the same logic as you implemented at the SQL Level:

image

So i can tweak the length as it fits best

Other one (if simpler) would be
if only one when condition exists and only 1 and/or condition, then use one line

like:

select
case when 1 = 1 then 'super' else 'bad' end as example, -- fits rule
case when 1 = 1 and 2 = 2 then 'super else 'bad' end as example_2, --fits rule
case 
       when  1 = 1 then 'super'
       when 2 = 2 then 'ok'
       else 'bad' 
end as example_3 -- does not fit rule
from test

Thanks
Ben


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

OK, will give it a try


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

Hi @benjamin-moeller,

grafik

Please give it a try

Regards

Guido

 


Reply
Page 1 / 3
Share: