Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does this mean? 1

Status
Not open for further replies.

Nancy2

Programmer
Sep 18, 2001
97
0
0
US
"SELECT * FROM adview WHERE 1=1 AND memid=11219 ORDER
BY ADID, positiontitle"

Can someone tell me what the WHERE 1=1 is doing? Of course no field named 1.

Thanks
 
This could have been a test case that was hard-coded into the query to validate the design/results. Other than that, I don't see this doing anything. I believe you can remove it without harm. htwh Steve Medvid
"IT Consultant & Web Master"
 
Thank you! That's what I suspected.
 

"WHERE 1=1" always evaluates to true. Sometimes, when dynamically building a SQL statement with optional WHERE criteria, I will use WHERE 1=1 and then concatenate the other criteria. This may have been done for a similar reason in your example.

Example:

sCrit1="Col2=12"
sCrit2=""
sCrit3="Col5='Denver'"

SQL = "Select * From Table Where 1=1 "

If sCrit1 <> &quot;&quot; Then
SQL = SQL & &quot; And &quot; & sCrit1
End If

If sCrit2 <> &quot;&quot; Then
SQL = SQL & &quot; And &quot; & sCrit2
End If

If sCrit3 <> &quot;&quot; Then
SQL = SQL & &quot; And &quot; & sCrit3
End If

This example creates this SQL statement:

Select * From Table Where 1=1 And col2=7 And col5='Denver'

If all three criteria are blank the statement (Select * From Table Where 1=1) will return all records. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top