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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Query 1

Status
Not open for further replies.

JayKusch

MIS
Joined
Oct 30, 2001
Messages
3,199
Location
US
Afternoon,

this is more of an FYI on my part. have several stored procedures as well as queries that have been written not in stored procedures. i find ni most of the code the statment:

1=1

as in:

Select * from WhatEver
Where date_entered = '10/31/01' and
name = 'Johns' and
1=1


there are no fields, in any tables, that are named "1", so i am rather confussed. they do use a primary key on all tables that is numeric and seeded from 1 by 1. does this play into the 1=1 syntax?

thanks



 
It's a trick used when SQL is embedded in asp/jsp/coldfusion pages. It allows the programmer to optionally add extra clauses preceeded with an operator without having to test if a clause is the 1st clause.

Searching for 'sql tricks 1=1' came up with:
or

By itself (i.e. without optional clauses) it's not necessary. also, in the example you gave where there are preceeding required clauses (i.e. name='John') it's also not necessary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top