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::

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.

Note 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>
    
<CFOUTPUT>
    The query returned #EmpList.RecordCount# records.
</CFOUTPUT>
</BODY>
</HTML>
  1. Save the file as emplist.cfm.
  2. View the page in a browser.

The number of employees now appears below the list of employees.

Code Review

You now display the number of records retrieved in the query.

Code Description
<CFOUTPUT>
Display what follows
The query returned
Display the text "The query returned"
#EmpList.RecordCount#
Display the number of records retrieved in the EmpList query
records.
Display the text "records"
</CFOUTPUT>
End the CFOUTPUT block.

Query Properties Notes and Considerations

Keep the following in mind when using query properties: