Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
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
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
what is the reason to force an unoptimized load?
A few items don't work as optimized loads. For example, mapping table loads. Can't recall others at the moment.
-Rob