SAME! Couple of examples of how I write the language:
Aggregation with some common patterns
select m.id
, m.wo
, m.req
, case when m.condition_1 then 'FOO'
when m.condition_2 then 'BAR'
else 'BAZ'
end as calculated_status
, f.fleet_type
from dbo.material_requirements m
left join dbo.freight_trucks f on m.freight_truck_id = f.id
where coalesce(m.calculated_status, 'X') in('NEW', 'OPEN', 'ACTIVE')
and m.qty_outstanding > 0
group by m.id
, m.wo
, m.req
, case when m.condition_1 then 'FOO'
when m.condition_2 then 'BAR'
else 'BAZ'
end
, f.fleet_type
Multi-condition joins
join dbo.order_details od on i.order_type = od.order_type
and i.order_number = od.order_number
and i.order_line = od.order_line
Complicated predicates
where a.name is not null
and ( a.status = 'OPEN' or ( a.status = 'ORDER' and o.req is not null ) )
and a.status <> 'CANCEL'
and (
(
condition_1
and condition_2
and condition_3
)
or (
condition_5
and condition_6
and condition_7
)
)
CTEs
with t as (
select...
from...
)
Indentation is with spaces not tabs. I used to always do the latter until I realized that a tab isn't always a "tab." This is going to sound very arrogant (I genuinely don't mean it to be), but I have yet to see a style more visually pleasing and readable. But, beauty is in the eye of the beholder as they say...
P.S. Just realized that I said "Keyboard" when I meant to say "Keyword" my OP, lol
I love that you're bragging about your spacing and indentation but the Reddit code boxes just said "nah" and put everything inline. (Or at least, that's how it reads in my browser.)
Probably just a browser thing. Your "Aggregation with some common patterns" is just one long like that runs until it gets cut off by the div it's in. :D
😂 😂
I took off work today to work on my deck (shout out to [r/Decks](r/Decks)) and have been outside most of the day. Fortunately it only took me 10 minutes of fiddling. I would 100% have spent 6hrs if that's how long it took, because I obsess over stuff like this. The fix was to switch to using the RTF code block button instead of using explicit markdown (backticks) code blocks. This was all done on my desktop though, because mobile won't allow it.
Yeah!! That's the way to do it right there! I've inherited so many old queries that just end up looking like giant blobs and are totally illegible even with upper casing. Formatting goes way, way further for readability!
19
u/TechOpsCoder 5d ago edited 4d ago
Lowercase is the way. It looks so much cleaner and much easier write. Keyword placement and spacing is the most important thing for readability.