Simon Sabin, fellow SQL MVP, has posted on the topic of formatting SQL.
For me, I align my queries vertically like so:
select track,
level,
title,
Name,
ss.length
from ConferenceSession cs
join session ss
on ss.sessionId = cs.SessionId
join Speaker sp
on sp.SpeakerId = ss.ownerId
where cs.Approved = 1
and cs.ConferenceId = 4
order by length,
title,
cs.SessionId desc
If I have multiple join predicates, I continue the indention pattern:
select track,
level,
title,
Name,
ss.length
from ConferenceSession cs
join session ss
on ss.sessionId = cs.SessionId
and (ss.approved = 1
or ss.track = 'DBA')
join Speaker sp
on sp.SpeakerId = ss.ownerId
where cs.Approved = 1
and cs.ConferenceId = 4
order by length,
title,
cs.SessionId desc
What is your SQL formatting style?