User Guide

Chapter 3: Querying a Database 27
When outputting the data itself, you define the variable name using the QUERY
attribute.
When outputting query properties variables, don’t use the QUERY attribute;
instead, prefix the variable reference with the name of the query, for example,
EmpList.RecordCount.
Columns must exist and be retrieved to the application in order to output their
values.
As with other attributes, surround the QUERY value with double quotes (").
As with any variables that you reference for output, surround column names
with pound signs (#) to tell ColdFusion to output the column’s current values.
Add a <BR> tag to the end of the variable references so that ColdFusion will
start a new line for each row that is returned from the query.
Getting Information About Query Results
Each time you query a database with the CFQUERY tag, you get not only the data itself,
but also query properties, as described in the following table::
To output query data on your page:
1. Return to emplist.cfm in Studio.
2. Edit the file so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Employee List</TITLE>
</HEAD>
<BODY>
<H1>Employee List</H1>
<CFQUERY NAME="EmpList" DATASOURCE="CompanyInfo">
SELECT FirstName, LastName, Salary, Contract
FROM Employees
</CFQUERY>
<CFOUTPUT QUERY="EmpList">
#FirstName#, #LastName#, #Salary#, #Contract#<BR>
</CFOUTPUT>
Query Properties
Property Description
RecordCount The total number of records returned by the query.
ColumnList Returns a comma-delimited list of the query columns.
CurrentRow The current row of the query being processed by CFOUTPUT.