3 ms·
I use this style. I work with queries that are a little bigger than average, and it's very difficult to keep track of it unless it's well laid out. conditional
by howItsDone123 10y ago
I use this style. I work with queries that are a little bigger than average, and it's very difficult to keep track of it unless it's well laid out.
conditionals, loops, etc, get formatted like they would in a procedural language. the DML gets formatted similarly to what you've posted.
a not unrealistic example from this morning is as follows:
if (select object_id('aTableName', 'u')) is not null begin
select column
from aTableName
where thisIsTrue = 1
and somethingIs in (select aList from aListTable)
and somethingElse = (
select aValue
from aValueTable
where aValue = 'somethingImportant'
)
end else begin
print('Oh noes! I couldn't find somethingImportant or something in someList form aTable!')
end
we work with huge amounts of data with systems and processes that don't lend themselves to other methods (yet... it's coming.) so we have to make SQL as readable as possible.
edit: yes... i know... subqueries are bad... it's just an example. those would have been done in joins or as temporary variables or something else.