Smart alignment -- ON plus AND/OR

20 Posts
3 Users
0 Reactions
177 Views
(@hwmonkey)
Member
Joined: 4 months ago
Posts: 7
Topic starter  

The join is arguably the most important part of SQL, and when one of our coders gets it wrong, the most troublesome. We implemented a formatting standard to expedite clarity of reading the joins for the really complex ones, that involve AND or OR. It really is just aligning the AND/OR keywords with the ON. Code would look something like:

 SELECT
     na.*
   , zian.abbr
   , net.field2
 FROM note_actions na
   INNER JOIN myschema.tbl_edit_trail  net  ON na.note_id  = net.note_id
   INNER JOIN myschema.tbl_emp         emp  ON emp.user_id = net.user_id
                                           AND emp.prac_id = na.prac_id
   INNER JOIN myschema.tbl_nose       zian  ON net.nose_c  = zian.note_c
                                            OR na.nose_c   = zian.note_c
 WHERE
     zian.abbr = 'CON'

Currently, I cannot figure out how to do this with SQLinForm


   
Quote
Guido
(@admin)
Member Admin
Joined: 3 years ago
Posts: 223
 

Hi @hwmonkey,

when a linebreak is inserted beforte AND/OR in a JOIN statement it starts at the left margin or at (left margin + one indent level). Its position is not based upon the position of the ON. But this sounds like a good idea for a future  release

grafik

Regards

Guido


   
ReplyQuote
(@hwmonkey)
Member
Joined: 4 months ago
Posts: 7
Topic starter  

Thanks @admin,

Thank you for the recommended settings. Thank you for considering this feature in a future release. Once a person gets used to it being formatted like this, it is remarkably easy to quickly debug/understand.


   
ReplyQuote
(@lompies)
Member
Joined: 3 weeks ago
Posts: 5
 

@admin I am a new happy user and this was the first thing I was looking for. Please add my vote!


   
ReplyQuote
Guido
(@admin)
Member Admin
Joined: 3 years ago
Posts: 223
 

@lompies , @hwmonkey

it took some time but now I have changed the logic for the AND/OR Alignment for JOIN Statements as required.

Would you like to do some Beta-Testing?

Regards

Guido


   
ReplyQuote
(@lompies)
Member
Joined: 3 weeks ago
Posts: 5
 

@admin Yes - sign me up!


   
ReplyQuote
(@hwmonkey)
Member
Joined: 4 months ago
Posts: 7
Topic starter  

Posted by: @admin

@lompies , @hwmonkey

it took some time but now I have changed the logic for the AND/OR Alignment for JOIN Statements as required.

Would you like to do some Beta-Testing?

1. Thank you

2. Rewriting sections of code can be challenging. I get it. And I appreciate it.

3. Answer: It depends on your timeline for implementation. I definitely am willing, but I am heavily committed to projects at the moment and I cannot commit to anything for probably 3 weeks.

 


   
ReplyQuote
Guido
(@admin)
Member Admin
Joined: 3 years ago
Posts: 223
 

@lompies , @hwmonkey

When you have some free time, you can test it by downloading the new Release (Desktop app or N++ Plugin) and use the higlighted option (see screenshot)

grafik

Thanks for your feedback and this great idea


   
ReplyQuote
(@hwmonkey)
Member
Joined: 4 months ago
Posts: 7
Topic starter  

@admin -- The screenshot makes me so happy. Thank you. And I hope other coders use it and discover how much easier it is to read when formatted like this.


   
ReplyQuote
(@lompies)
Member
Joined: 3 weeks ago
Posts: 5
 

@admin Cannot get it to work? See video


   
ReplyQuote
Guido
(@admin)
Member Admin
Joined: 3 years ago
Posts: 223
 

I can't see any AND/OR keywords in the ON clauses. Please add a few AND/OR clauses and it should work


   
ReplyQuote
Guido
(@admin)
Member Admin
Joined: 3 years ago
Posts: 223
 

... and please remove the linebreak before "ON"


   
ReplyQuote
(@hwmonkey)
Member
Joined: 4 months ago
Posts: 7
Topic starter  

@admin I did one quick test. My assumption was that all of the ON statements would align. That is not what happened.

select
    *
FROM dbs.clr_tdl_tran ttr
    INNER JOIN dbs.ptr pat ON ttr.int_pat_id                   = pat.pat_id
                          and 1                                =1
    LEFT OUTER JOIN dbs.valid_ptr vpat ON pat.pat_id           = vpat.pat_id
    INNER JOIN dbs.account a           ON ttr.account_id       = a.account_id
    INNER JOIN dbs.clr_ser ser         ON ttr.performing_pr_id = ser.emm_pr_id
                               or ttr.dog                      = ser.cat
    INNER JOIN dbs.clr_ser bser ON ttr.billing_prider_id       = bser.emm_pr_id
    INNER JOIN dbs.clr_dep dep  ON ttr.dept_id                 = dep.department_id

   
ReplyQuote
(@lompies)
Member
Joined: 3 weeks ago
Posts: 5
 

@admin I tried that.

image

It looks like you are aligning the = signs not the OR?

I don't understand the conditions - remember I'm not a coder

image

Why are there two columns?


   
ReplyQuote
(@lompies)
Member
Joined: 3 weeks ago
Posts: 5
 

This looks the way I like it!

Maybe I had spaces in the first example.

How do I get the AS to align?

image

   
ReplyQuote
Page 1 / 2
Share: