User Guide
24 Developing Web Applications with ColdFusion
Building Queries
As discussed earlier in this chapter, you build queries using the CFQUERY tag and SQL.
To query the table:
1. Create a new application page.
2. Edit the page so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Employee List</TITLE>
</HEAD>
<BODY>
<H1>Employee List</H1>
4 <CFQUERY NAME="EmpList" DATASOURCE="CompanyInfo">
4 SELECT FirstName, LastName, Salary, Contract
4 FROM Employees
4 </CFQUERY>
</BODY>
</HTML>
3. Save the page as emplist.cfm in myapps under the Web root directory. For
example, the directory path on your machine may be:
C:\INETPUB\WWWROOT\myapps on Windows NT
4. Return to your browser and enter the following URL to view
EmpList.cfm:
http://127.0.0.1/myapps/emplist.cfm
5. View source in the browser.
The ColdFusion EmpList data set is created by ColdFusion Server, but only HTML
and text is sent back to the browser. To display the data set on the page, you must
code tags and variables to output the data.
Code Review
The query you just created retrieves data from the CompanyInfo database.
Code Description
<CFQUERY NAME="EmpList"
DATASOURCE="CompanyInfo">
Query the database specified in the
CompanyInfo datasource
SELECT FirstName, LastName,
Salary, Contract
FROM Employees
Get information from the FirstName,
LastName, Salary, and Contract fields in
the Employees table
</CFQUERY>
End the CFQUERY block