Chad,
Here is what I do in that situation. First my select statement by default
will return all rows

SELECT *
FROM FlexoDirectConfigFiles
WHERE 1=1

1 will always be eqal to 1 so this is an easy way of getting all records and
allowing for optional and clauses then you can do this; Pass in optional
arguments to your function. You want to make these arguments not required
that way can pass as many or as few filters to your function as possible.
The code below may not be right I just threw it together quickly, but
hopefully you get the idea.

<cfargument name="arg1" type="string" required="false">
<cfargument name="arg1" type="string" required="false">


<cfquery ...>
SELECT *
FROM FlexoDirectConfigFiles
WHERE 1=1
<cfif structKeyExists(arguments,"arg1")>
AND column = <cfqueryparam value="#arguments.arg1#">
</cfif>
<cfif structKeyExists(arguments,"arg2")>
AND column = <cfqueryparam value="#arguments.arg2#">
</cfif>
</cfquery>



On 7/18/07, Chad Gray <[EMAIL PROTECTED]> wrote:
>
> I have a CRUD CFC that has this function and I load the CFC into the
> application scope:
>
> <cffunction name="readZJF" access="public" returntype="query">
>         <cfargument name="criteria" type="string" required="yes">
>
>         <cfquery datasource="dsn" name="readZJF">
>         SELECT *
>         FROM FlexoDirectConfigFiles
>         WHERE #arguments.criteria#
>         </cfquery>
>
>         <cfreturn readZJF>
> </cffunction>
>
> I want to be able to pass in the "WHERE" statement into it.  So it could
> be:
> FileName = 'PLATES.zjf' AND FileModificationDate = '09/30/2005 12:34:01
> PM'
>
> So I run something like this to call the function:
>
> <cfset DoesFileAlreadyExist = application.ZJF.readZJF("FileName =
> '#getZJF_files.name#' AND FileModificationDate =
> '#getZJF_files.dateLastModified#'")>
>
> What I get back is an error:
> [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '
> PLATES.zjf'.
>
> Then I look at the SQL that was run in debugging.
> SELECT *
> FROM FlexoDirectConfigFiles
> WHERE FileName = ''PLATES.zjf'' AND FileModificationDate = ''09/30/2005
> 12:34:01 PM''
>
> Why did it take my single quotes and add another single quote?  Is it
> trying to escape the single quote?  How do I keep it from doing this?
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion 8 beta – Build next generation applications today.
Free beta download on Labs
http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_adobecf8_beta

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

Reply via email to