PreserveSingleQuotes

Prevents ColdFusion from automatically "escaping" single quotes contained in variable.

Syntax

PreserveSingleQuotes(variable)
variable

Variable containing the string for which single quotes are preserved.

Usage

PreserveSingleQuotes is useful in SQL statements.

Example

<!-----------------------------------------------------------
This example shows the use of QuotedValueList, ValueList, and
PreserveSingleQuotes.
------------------------------------------------------------->
<HTML>
<HEAD>
<TITLE>
PreserveSingleQuotes Example
</TITLE>
</HEAD>

<BODY>
<H3>PreserveSingleQuotes Example</H3>

<!--- use the contents of one query to create another
dynamically --->
<CFSET List="'Sales','Training','HR'">

<!--- first, get the department ids in our list --->
<CFQUERY NAME="GetDepartments" DATASOURCE="HRApp">
SELECT Department_ID
FROM Departments
WHERE Department_Name IN (#PreserveSingleQuotes(List)#)
</CFQUERY> 

<!------------------------------------------------------ 
now,  find the employees in the departments based
on the  previous query. 
-------------------------------------------------------->
<CFQUERY NAME="GetEmployees" DATASOURCE="HRApp">
SELECT     Employee_ID, FirstName, LastName, Department_ID
FROM     Employees
WHERE     Department_ID IN (#ValueList(GetDepartments.Department_ID)#)
</CFQUERY>
<!------------------------------------------------------ 
Now,  find the employees in the departments based
on the  previous query, using QuotedValueList. 
-------------------------------------------------------->
<CFQUERY NAME="GetEmployeeInfo" DATASOURCE="HRApp">
SELECT     FirstName, LastName, Department_ID, StartDate
FROM     Employees
WHERE     LastName IN (#QuotedValueList(GetEmployees.LastName)#)
        AND FirstName IN (#QuotedValueList(GetEmployees.FirstName)#)
        
</CFQUERY>
<!--- now, output the results --->
<CFOUTPUT QUERY="GetEmployeeInfo" >
#FirstName#    #LastName#    (#Department_ID# )    <BR>
</CFOUTPUT>
</BODY>
</HTML>