Skip to main content
Inspiring
July 25, 2008
Question

Where clause in SQL server

  • July 25, 2008
  • 3 replies
  • 559 views
Hi all,
Can someone explain this to me in plain english? The line ' WHERE 1 = 2 '
I am new to these concepts...
This topic has been closed for replies.

3 replies

Participating Frequently
July 29, 2008
Where clause is a condition statement.
For nice music visit http://musiktag.eu
emmim44Author
Inspiring
July 25, 2008
it makes sense. thank you man
Inspiring
July 25, 2008
emmim44 wrote:
> Hi all,
> Can someone explain this to me in plain english? The line ' WHERE 1 = 2 '
> I am new to these concepts...
>
> <cfquery name="getTeam" datasource="#application.DSN#">
> SELECT *
> FROM CCFTeam
> <cfif this.team_id eq "">
> WHERE 1 = 2
> <cfelse>
> WHERE CCFTeamID IN (<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
> value="#this.Team_ID#" list="yes">)
> </cfif>
> </cfquery>
>

If this.team is an empty string then WHERE 1=2. I.E. if no team return
no rows because 1=2 will always by false.

This code is a bit strange because that type of construct is usually
used with AND|OR compound WHERE clauses. I would have possibility
written this code in this way.

WHERE 1 = 2
<cfif len(trim(this.team)) GT 0>
OR CCFTeamID IN (<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
value="#this.Team_ID#" list="yes">)
</cfif>

I.E. Return no rows unless this.team contains one or more values.