Writing Sql - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

Chapter 3: Querying a Database
Performs SQL commands that are enclosed within the block.
Returns query variable values to the page.
CFQUERY tag syntax
<CFQUERY NAME="EmpList" DATASOURCE="CompanyInfo">
You'll type SQL here
</CFQUERY>
In this example, the query code tells ColdFusion to:
Use the
Store the retrieved data in the query variable EmpList.
In general, you should follow these guidelines:
The CFQUERY tag is a block tag, that is, it has an opening <CFQUERY> and
ending </CFQUERY> tag.
Use the NAME attribute to name the query variable so that you can reference it
later on the page.
Use the DATASOURCE attribute to name an existing data source that should be
used to connect to a specific database.
Always surround attribute values with double quotes (").
Place SQL statements inside the CFQUERY block to tell the database what to
process during the query.
When referencing text literals in SQL, use single quotes ('). For example,
* from mytable WHERE FirstName='Russ'
in which the first name is Russ.
Note

Writing SQL

In between the begin and end CFQUERY tags, write the SQL that you want the
database to execute.
For example, to retrieve data from a database:
Write a SELECT statement that lists the fields or columns that you want to
select for the query.
Follow the SELECT statement with a FROM clause that specifies the database
tables that contain the columns.
Tip
data source to connect to the
CompanyInfo
The data source must exist in order to perform a successful query.
If you are using ColdFusion Studio, you can use the Query Builder to
build SQL statements by graphically selecting the tables, and records
within those tables you want to retrieve. See Using ColdFusion Studio for
details.
database.
company.mdb
selects every record from mytable
21
Select

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion 4.5

Table of Contents