×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

where 0 = 0

where 0 = 0

where 0 = 0

(OP)
An old program has this statement
select * from db1 where 0 = 0

Why "where 0 = 0" is needed?

RE: where 0 = 0

Could be many reasons.  Could be that if the program is or was concatenating other criteria to the where clause, they didn't want the application logic to figure out whether or not to put the word WHERE or the word AND (or even OR).  

Consider the following pseudocode:

CODE

String sql = "select * from db1 where 0 = 0"
If CheckBox1 Is Checked Then sql = sql + " AND Col1 =" + TextBox1
If CheckBox2 Is Checked Then sql = sql + " AND Col2 =" + TextBox2

RE: where 0 = 0

WHERE 0=0 (or the more frequently seen WHERE 1=1) is used exactly as riverguy says, to append optional additional AND conditions

to append OR conditions, however, you'd use WHERE 0=1

smile

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: where 0 = 0

RiverGuy and r937 are correct in why such a thing might occur but it may not be the best of approaches. Things like 0=0 or 0=1 will be evaluated on every record even though the result never changes. That can slow execution. If concatenation of clauses is required then something like (in no particular language) ...

CODE

If WhereClause = "" Then
   WhereClause = "WHERE " & SubClause
Else
   WhereClause = WhereClause & " AND " & SubClause
End If
avoids the use of dummy WHERE conditions.

RE: where 0 = 0

Quote:

Things like 0=0 or 0=1 will be evaluated on every record
database optimizers are smart enough to "optimize away" those types of conditions

heck, even mysql can do that    winky smile


your if/else code block would have to be applied to every form field

too many trees, not enough forest  

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close