My main use is that it makes it easier to comment out stuff during development of queries. I lead with ,
's and and
's:
SELECT
A
-- ,B
,C
,D
-- ,E
FROM TABLE
WHERE 1=1
-- and B='This'
and C='That'
-- and D is not null
Also makes it easier to programmatically tack stuff unto the end.
this = "SELECT * "
this += "FROM TABLE "
this += "WHERE 1=1 "
if user chooses option a then this += "and A is not null "
if user chooses option b then this += "and B is not null "
if user chooses option b then this += "and C is not null "
if user chooses option b then this += "and D is not null "
Otherwise you'd have to qualify the first option... and have each following option check the previous options. What if the user only chose Option D in the previous example? You'd have to make sure that if A, B and C aren't chosen
then use WHERE
else use and
. With =
at the start, you can just slap the qualifiers to the end of the statement.