User Guide

54 Chapter 4 Retrieving and Formatting Data
Reviewing the code
The following table describes the highlighted code and its function:
Code Description
SELECT Departmt.Dept_Name,
Employee.FirstName,
Employee.LastName,
Employee.StartDate,
Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID =
Employee.Dept_ID
Retrieve the fields listed from the
Departmt and Employee tables, joining
the tables based on the Dept_ID field in
each table.
<cfif IsDefined("FORM.Department")>
AND Departmt.Dept_Name =
#Form.Department#
</cfif>
If the user specified a department on
the form, only retrieve records where
the department name is the same as
the one the user specified. Note that
you need the pound signs in the SQL
AND statement to identify
Form.Department as a ColdFusion
variable, but not in the IsDefined
function.
<cfif Form.LastName IS NOT "">
AND Employee.LastName =
#Form.LastName#
</cfif>
If the user specified a last name in the
form, only retrieve the records in which
the last name is the same as the one
the user entered in the form.