News for hackers. Stuff that matters.
Re:Best practices for writing SQL queries by mactrey on Saturday April 10, 2021 @02:47PM (#26763926)
I'm so attached to starting all my where clauses with a TRUE (1=1 since SQL Server doesn't have boolean literals) that I do this when I need some OR clauses:

    SELECT foo
    FROM bar
    WHERE 1=1
      AND (1<>1
           OR baz > boom
           OR fizz >= bang
           )
      AND foo is not null
So you can comment out lines starting with OR individually. Some people might hate it but it makes sense conceptually for me since almost every query I write takes a chain of ANDs in the where clause as a starting point.

There are no comments on this comment yet.