If I may interject, Brooks, I'm curious that you chose to show use of the
wildcard SQL statements, since he didn't indicate needing that. No offense
intended. I realize you must have read his requirements as needing them, but
it doesn't seem he was. I'm just saying this in case other newcomers may
come along and read this (perhaps even in the archive). You generally want
to avoid the wildcards unless you really need them. See the docs or any CF
or SQL book to explain what they (% used in SQL) are about.
 
Also, in your second example, you show a line like this:
 
    <cfif len(trim(myArgument1))>   and column1 = 'myArgument1'</cfif> 

Looks like you left out the pound signs around the second myArgument1.
Again, I'm not picking on you. I just wouldn't want any newcomer to think
that somehow SQL and variables within a CFC has different rules.  I realize
that's a stretch, but having worked with lots of newcomers, I've learned to
be as explicit about such things as possible.
 
As for a good solution for to Anthony's problem, I liked Allen's of the lot
so far. I'll comment on that in a moment.
 
/Charlie
http://www.carehart.org/blog/  

 


  _____  

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Friday, February 02, 2007 12:05 PM
To: [email protected]
Subject: Re: [ACFUG Discuss] CFC and reuse query



Anthony: 

If you have three columns that you want to query on you, can do the
following: 

<cfcomponent> 
  <cffunction name="myFunction" access="public" returntype="string"> 
    <cfargument name="myArgument1" type="string" required="yes"> 
    <cfargument name="myArgument2" type="string" required="yes"> 
    <cfargument name="myArgument3" type="string" required="yes"> 
    <cfset myResult="foo"> 

<cfquery name="qFoo" datasource="datasource"> 

select * 
  from fooTable 
 where 1=1 
   and column1 = '%myArgument1%' 
   and column2 = '%myArgument2%' 
   and column3 = '%myArgument3%' 

</cfquery> 

<!--- or you could do: (this avoids wild cards) ---> 

<cfquery name="qFoo" datasource="datasource"> 

select * 
  from fooTable 
 where 1=1 
 <cfif len(trim(myArgument1))>   and column1 = 'myArgument1'</cfif> 
 <cfif len(trim(myArgument2))>   and column2 = 'myArgument2'</cfif> 
 <cfif len(trim(myArgument3))>   and column3 = 'myArgument3'</cfif> 

</cfquery> 


    <cfreturn myResult> 
  </cffunction> 
</cfcomponent> 

Sincerely,

Brooks Wilson 



-------------------------------------------------------------
To unsubscribe from this list, manage your profile @ 
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------

<<attachment: att60441.jpg>>

Attachment: ATT00972.gif
Description: GIF image

Reply via email to