I agree 100% as I have done this as well. 

-----Original Message-----
From: Aaron Rouse [mailto:[EMAIL PROTECTED] 
Sent: Saturday, October 06, 2007 3:32 PM
To: CF-Talk
Subject: Re: CF Code readability (Where Clause)

I do this a lot for my search queries, the only difference is I usually have
after WHERE 0 = 0, a loop over say all my varchar column names I may be
searching on then I do a check to see if the key exists in the structure I
am searching on and if it has a value to build a AND COLUMN LIKE '%asd%' or
something to that effect.

On 10/6/07, Thomas Flagg <[EMAIL PROTECTED]> wrote:
>
> Don't forget--another trick you can use if/when using IF or CASE logic 
> within your CFML pages, you can do the following as a trick:
>
> SELECT *
> FROM TABLE
> WHERE 1=1
> <cfif condition 1>
> AND CONSTRAINT 1
> </cfif>
> <cfif condition 2>
> AND CONSTRAINT 2
> </cfif>
> <cfif condition 3>
> AND CONSTRAINT 3
> </cfif>
> <cfif condition 4>
> AND CONSTRAINT 4
> </cfif>
>
>
> The benefit of adding the 1=1 is that it always returns true and has 
> no negative impact on the query results or performace.  Furthermore, 
> it allows you to focus on the conditions in such a way that you do  
> not have to add addtional logic to handle the begining AND in the WHERE
clause.
>
> Thomas
>
> >How many use the query coding (where clause) as:
> >
> >where
> >            x = 1 and
> >            Deleted = 0
> >
> >
> >OR
> >
> >
> >where
> >        x = 1
> >        and Deleted = 0
> >
> >
> >
> >I prefer the second one as if I need to remove or simply comment the 
> >line out for testing, I only do the one line rather than having the 
> >comment
> tags
> >skew over multiple lines?
> >
> >Thanks for your input.
>
> 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade to ColdFusion 8 and integrate with Adobe Flex
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290468
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to