[thelist] CF / SQL problem

Scott_Brady@themoneystore.com Scott_Brady at themoneystore.com
Tue, 21 Dec 1999 16:23:32 -0800


I'm working on a CF form that would allow a user to search an Access database
based on a variety of criteria.  One of those criteria is by searching for a
department (text field).

Because the search string is dynamically generated (depending on how many
criteria they choose to search on), I am using <cfset>'s to generate the string
and then putting that string between the <cfquery> tags.  Everything works
except for searching on that text field ( "department" ).  When a value is
entered into that field, I get a Syntax Error or Access Violation in Cold
Fusion.  If I take copy the string that is generated and hard-code it into the
query, it works fine.

Everyone I've asked is stumped.

I'd be grateful for any assistance.

Here is code where I generate part of the string:

<cfset qryString = "SELECT * FROM mailcodeTB, divisionTB, stateTB, sacramentoTB
WHERE mailcodeTB.divisionID = divisionTB.divisionID AND mailcodeTB.stateID =
stateTB.stateID AND mailcodeTB.sacID = sacramentoTB.sacID">
<cfswitch expression="#department#">
     <cfcase value=" ">
     </cfcase>
     <cfdefaultcase>
          <cfset qryString = Insert(" AND mailcodeTB.department LIKE
'#department#%'", qryString, Len(qryString))>
     </cfdefaultcase>
</cfswitch>


Here's where I run the query:

<cfquery name="get_codes" datasource="#datasourse#">
     <cfoutput>#qryString#</cfoutput>
</cfquery>


Any ideas from you Cold Fusion gurus out there?

Thanks!

Scott Brady