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
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
Regards
Guido
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.
@admin I am a new happy user and this was the first thing I was looking for. Please add my vote!
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.
@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.
I can't see any AND/OR keywords in the ON clauses. Please add a few AND/OR clauses and it should work
... and please remove the linebreak before "ON"
@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
@admin I tried that.
It looks like you are aligning the = signs not the OR?
I don't understand the conditions - remember I'm not a coder
Why are there two columns?
This looks the way I like it!
Maybe I had spaces in the first example.
How do I get the AS to align?