MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual page 56

Table of Contents

Advertisement

36
To use the results of a query in a query:
1
2
3
4
5
Create a new application page in ColdFusion Studio.
Edit the page so that it appears as follows:
<html>
<head>
<title>Using Query Results in a Query</title>
</head>
<body>
<h1>Employee List</h1>
<!--- LastNameSearch normally would be generated interactively --->
<cfset LastNameSearch = "Jones">
<!--- Normal query --->
<cfquery datasource = "CompanyInfo" name = "EmpList"
cachedwithin=#CreateTimeSpan(0,1,0,0)#>
SELECT *
FROM Employee
</cfquery>
<!--- Query using query results --->
<cfquery dbtype = "query" name = "QueryFromQuery" >
SELECT Emp_ID, FirstName, LastName
FROM EmpList
WHERE LastName = '#LastNameSearch#'
</cfquery>
Output using a query of query<br>
<cfoutput query = QueryFromQuery>
#Emp_ID#: #FirstName# #LastName#<br>
</cfoutput>
<br>
Columns in the Emplist database query<br>
<cfoutput>
#Emplist.columnlist#<br>
</cfoutput>
<br>
Columns in the QueryFromQuery query<br>
<cfoutput>
#QueryFromQuery.columnlist#<br>
</cfoutput>
</body>
</html>
Save the page as queryquery.cfm in myapps under the Web root directory.
Return to your browser and enter the following URL to view the results of the
query:
http://127.0.0.1/myapps/queryquery.cfm
View the source in the browser.
Chapter 3 Querying a Database

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents