2 Replies Latest reply: May 14, 2012 7:12 PM by Rob Wunderlich RSS

    where 1=1?

      I have seen that some people write

       

      "select

           lastname

           firstname

      from

           customer

      where 1=1"

       

      The purpose of haveing "where 1=1"? What result would it gain?

        • where 1=1?

          I believe this is used to generate a permanently 'true' boolean statement,  perhaps to force that a database to return a resulset. However this shouldn't be necessary unless the database from which you are getting data is buggy, and doesn't return data sometimes, using a statement that forces a "true" on the query, may get the job done.

           

          best

          • where 1=1?
            Rob Wunderlich

            As Jorge indicated, it's an "always true" clause. It logically has the same effect as no where clause. I've seen two uses in QV script.

             

            1. As a placeholder, commonly used when variables are used to generate the SQL statement. The WHERE is a fixed bit of text and the 1=1 avoids a syntax error when you want no clause.

             

            2. As a way to force an unoptimized load from a QVD. In that case you would see it in a LOAD statement rather than a SQL SELECT.

             

            -Rob