macromedia.coldfusion.database_access
[Top] [All Lists]

Re: Where clause in SQL server

Subject: Re: Where clause in SQL server
From: Ian Skinner <iskinner@xxxxxxxxxxx>
Date: Fri, 25 Jul 2008 07:40:08 -0700
Newsgroups: macromedia.coldfusion.database_access


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.

<Prev in Thread] Current Thread [Next in Thread>