If the regular stuff is large, you can even do:

<cfquery name="qFoo">
  select regular stuff
  <cfif something_is_true>
UNION select extra stuff I need
      (or maybe jus add to one or more clauses)
  </cfif>
</cfquery>

Depending on what you need to add it may be less readable than your
example. There could also be performance differences. But it is easier
to maintain.

Pascal

> -----Original Message-----
> From: Coleman, Brian [mailto:[EMAIL PROTECTED]
> Sent: zaterdag 19 juni 2004 1:37
> To: CF-Talk
> Subject: RE: dynamic query names
>
> Ya know that does make sense :P
>
> It's the same exact thing without the union and adjusting the
> is_true query with a few more lines of code
>
> I think I was using some faulty logic
>
>  
>
> <cfif something_is_true>
>
>     <cfquery name="qFoo">
>
>             select extra stuff I need
>
>     </cfquery>
>
> <cfelse>
>
>     <cfquery name="qFoo">
>
>             select regular stuff
>
>     </cfquery>
>
> </cfif>
>
>  
>
> thanks
>
>  
>
>  
>
> -----Original Message-----
> From: Dave Watts [mailto:[EMAIL PROTECTED]
> Sent: Friday, June 18, 2004 6:18 PM
> To: CF-Talk
> Subject: RE: dynamic query names
>
>  
>
> > I have a general query set up for a page
> >
> > If certain parameters are not met, that query named, for example,
> > Query1 is used
> >
> > If the parameters are met, then a second query called Query2 is ran
> > and the contents of that Query are joined with a Union statement to
> > the first query and Query3 is produced. (so there's more
> data on the
> > page)
> >
> > So in effect, either Query1 or Query3 is going to be the query that
> > will be used to produce the data on the page.
>
> You should be able to just use the same name again if you need to:
>
> <cfquery name="qFoo" ...>
> ...
> </cfquery>
>
> <cfif something_is_true>
> <cfquery name="qBar" ...>
> ...
> </cfquery>
> <cfquery name="qBaz" dbtype="query">
> SELECT * FROM qFoo
> UNION
> SELECT * FROM qBar
> </cfquery>
> <cfset qFoo = qBaz>
> </cfif>
>
> <cfoutput query="qFoo">...
>
> But, honestly, there's probably a more efficient and simple
> way to do whatever it is you're doing. Why not just run one
> query or another, rather than one query and another, unless
> they're in different (unlinkable) databases?
>
> Dave Watts, CTO, Fig Leaf Software
> http://www.figleaf.com/
> phone: 202-797-5496
> fax: 202-797-5444
>
>   _____  
>
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to