Skip to main content
November 15, 2006
Question

Query with an apostraphe

  • November 15, 2006
  • 3 replies
  • 338 views
I want to create a query such as the following:

<cfquery>
select question
from table
where question='What's your favorite color?'
</cfquery>

I keep getting an error message because of the apostraphe in What's.

How can I create this query so that it will work? These questions are submitted users, so I don't think I can say, just don't use an apostraphe.

Thanks.


This topic has been closed for replies.

3 replies

Participating Frequently
November 15, 2006
For your reference, please check the function "PreserveSingleQuotes()" in this document.

http://www.adobe.com/livedocs/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000353.htm

Thanks

Sankalan
(www.mindfiresolutions.com)
Participating Frequently
November 15, 2006
You can also use function PreserveSingleQuotes()

Thanks

Sankalan
(www.mindfiresolutions.com)
November 15, 2006
This works:

<CFSET sQuestion = "What's your favorite color?">
<CFQUERY>
select question
from table
where question='#sQuestion#'
</CFQUERY>



And so does this:

<CFQUERY>
select question
from table
where question='What''s your favorite color?'
</CFQUERY>