O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Advanced SQL

This section moves beyond the basic database manipulation techniques we discussed in earlier chapters. Here, we’ll cover methods for creating dynamic SQL, creating and modifying database tables using SQL, using aggregate and scalar functions, performing table unions and joins, and several other database-manipulation techniques. These are the kinds of operations that allow you to interact with databases at a higher level. Most advanced applications such as shopping carts, threaded discussion lists, and business-to-business applications use one or more of the techniques described in this section.

Dynamic SQL

An extremely powerful feature of ColdFusion is the ability to generate dynamic SQL queries based on a variety of inputs. In Chapter 3, you learned how to pass a single dynamic value in an SQL statement:

SELECT Name, Title, Department
FROM EmployeeDirectory
WHERE ID = #ID#

We extend this concept a bit in Example 11-9 to allow for completely dynamic SQL in the WHERE clause of a SQL statement.

Example 11-9. HTML Form for Searching Database Records

<!--- query the EmployeeDirectory table for a list of departments ---> <CFQUERY NAME="GetDepartments" DATASOURCE="ProgrammingCF"> SELECT DISTINCT Department FROM EmployeeDirectory ORDER BY Department </CFQUERY> <H2>Locate a User</H2> <FORM ACTION="Search.cfm" METHOD="post"> <TABLE> <TR> <TD>Name:</TD> <TD><INPUT TYPE="text" NAME="Name" SIZE="20" MAXLENGTH="80"></TD> </TR> <TR> <TD>Title:</TD> <TD><INPUT TYPE="text" NAME="Title" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required