Dynamic Sql - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

Chapter 5: Making Variables Dynamic
Example: Checking data types
<!--------------------------------------------------------------------
This example shows the use of CFQUERYPARAM when valid input is given in
Dept_ID.
----------------------------------------------------------------------->
<HTML>
<HEAD>
<TITLE>CFQUERYPARAM Example</TITLE>
</HEAD>
<BODY>
<H3>CFQUERYPARAM Example</H3>
<CFSET Course_ID=12>
<CFQUERY NAME="getFirst" DataSource="CompanyInfo">
SELECT *
FROM departments
WHERE Dept_ID=<CFQUERYPARAM VALUE="#Dept_ID#"
CFSQLTYPE="CF_SQL_INTEGER">
</CFQUERY>
<CFOUTPUT QUERY="getFirst">
<p>Department Number: #number#<br>
Description: #descript#
</P>
</CFOUTPUT>
</BODY>
</HTML>

Dynamic SQL

Embedding SQL queries that use dynamic parameters is a powerful mechanism for
linking variable inputs to database queries. However, in more sophisticated
applications, you will often want user inputs to determine not only the content of
queries but also the structure of queries.
Dynamic SQL allows you to dynamically determine (based on runtime parameters)
which parts of a SQL statement are sent to the database. So if a user leaves a search
field empty, for example, you could simply omit the part of the WHERE clause that
refers to that field. Or, if a user does not specify a sort order, the entire ORDER BY
clause could be omitted.
Dynamic SQL is implemented in ColdFusion by using CFIF, CFELSE, CFELSEIF tags to
control how the SQL statement is constructed, for example:
53

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?

This manual is also suitable for:

Coldfusion 4.5

Table of Contents