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. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Enterprise web applications, build robust, secure scalable apps today - Try it now ColdFusion Today ColdFusion 8 beta - Build next generation apps Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290458 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

