Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to figure out triple quotes

Status
Not open for further replies.

bobsmith123

IS-IT--Management
Jan 17, 2006
7
0
0
US
I am trying to build an SQL query dynamically, I know this is not a good idea, but its for an ad-hoc report. And I am getting hung up on needing quotes around some of the variables. For example, I am passing in a variable from a form, #form.name# and I am tryingt to build a query in the following way

<cfset strQuery = "SELECT ID FROM TABLE ">
<cfset strQueryWhere = "WHERE firstName = '#form.name'">
<cfset query = #strQuery# & #strQueryWhere#>

<cfquery name="myQuery" datasource="myDataSource">
#query#
</cfquery>


Now, I have a feeling it has to do with how the quotes are in te strQueryWhere variable, but I cannot figure it out. This works for integers, just not for strings that need quotes around them. Any help would be appreciated. Thanks.
 
if you do it that way you need to use the preserveSingleQuotes() function.

<cfquery>
#preserveSinglequotes(query)#
</cfquery>

but why not just build it dynamically right in the cfquery tags?

<cfquery>
Select #form.fields#
from #form.table#
where 0=0
<cfif len(trim(form.filter))>
and #form.colName# = '#form.filter#'
</cfif>
</cfquery>

you don't run into the preservesinglequotes problem much this way.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
a query what way? there's more than one way presented....

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top