User Guide

284 Chapter 2: ColdFusion Tags
This tag creates a query object, providing this information in query variables:
You can cache query results and execute stored procedures. For information about this and about
displaying
cfquery output, see Developing ColdFusion MX Applications.
The Caching page of the ColdFusion MX Administrator specifies the maximum number of
cached queries. Setting this value to 0 disables query caching.
You cannot use ColdFusion reserved words as query names.
You cannot use SQL reserved words as variable or column names in a Query of Queries, unless
they are escaped. The escape character is the bracket []; for example:
SELECT [count] FROM MYTABLE.
For a list of reserved keywords in ColdFusion MX, see Chapter 22, “Using Query of Queries,” in
Developing ColdFusion MX Applications.
Database query results for date and time values can vary in sequence and formatting, unless you
use functions to format the results. To ensure that customers using your ColdFusion application
are not confused by the display, Macromedia recommends that you use the
DateFormat and
TimeFormat functions to format values from queries. For more information and examples, see
TechNote 22183, "ColdFusion Server (5 and 4.5.x) with Oracle: Formatting Date and Time Query
Results," at www.coldfusion.com/Support/KnowledgeBase/SearchForm.cfm.
Example
<!--- This example shows the use of CreateTimeSpan with CFQUERY ------>
<!--- define startrow and maxrows to facilitate 'next N' style browsing ---->
<cfparam name="MaxRows" default="10">
<cfparam name="StartRow" default="1">
<!--------------------------------------------------------------------
Query database for information if cached database information has
not been updated in the last six hours; otherwise, use cached data.
--------------------------------------------------------------------->
<cfquery
name="GetParks" datasource="cfsnippets"
cachedwithin="#CreateTimeSpan(0, 0, 6, 0)#">
SELECT PARKNAME, REGION, STATE
FROM Parks
ORDER BY ParkName, State
</cfquery>
<!---- build HTML table to display query ------------------------->
<table cellpadding="1" cellspacing="1">
<tr>
<td colspan="2" bgcolor="f0f0f0">
<b><i>Park Name</i></b>
</td>
<td bgcolor="f0f0f0">
<b><i>Region</i></b>
</td>
Variable name Description
query_name.currentRow Current row of query that
cfoutput is processing
query_name.columnList Comma-delimited list of the query columns
query_name.RecordCount Number of records (rows) returned from the query
cfquery.ExecutionTime Cumulative time required to process the query