User Guide

Chapter 4: Retrieving and Formatting the Data You Want 35
But when you want to return information about employees that match user search
criteria, you use the SQL WHERE clause with a SQL SELECT statement to compare a
value against a character string field. When the WHERE clause is processed, it filters
the query data based on the results of the comparison.
For example, to return employee data for only employees with the last name of Allaire,
you would build a query that looks like this:
<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
SELECT FirstName, LastName, Contract
FROM Employees
4 WHERE LastName = ’Allaire’
</CFQUERY>
However, instead of putting the LastName directly in the SQL WHERE clause, you can
use the text the user entered in the form for comparison:
<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employees
4 WHERE LastName=’#Form.LastName#’
</CFQUERY>
Creating Action Pages
To create an action page for the form:
1. Create a new application page in Studio.
2. Enter the following code:
<HTML>
<HEAD>
<TITLE>Retrieving Employee Data Based on Criteia from Form</TITLE>
</HEAD>
<BODY>
<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employees
WHERE LastName=’#Form.LastName#’
</CFQUERY>
<H4>Employee Data Based on Criteria from Form</H4>
<CFOUTPUT query="GetEmployees">
#FirstName#
#LastName#
#Salary#<BR>
</CFOUTPUT>
</BODY>
</HTML>
3. Save the page as actionpage.cfm within the myapps directory.
4. View
formpage.cfm in your browser.