Basic HTML version of Foils prepared May 3 1998

Foil 54 Dynamic SQL - II

From Java Blend and Cold Fusion High Level Database Interfaces CPS616 Web Technologies -- Spring 98. by Chao Wei Ou


For example, in the following code, a series of CFIF tags determine which SQL statements to append to the base SQL SELECT statement:
<CFQUERY NAME="EmpList" DATASOURCE="CF 3.0 Examples">
SELECT * FROM Employees WHERE 0=0
<CFIF #LastName# is not "">
AND LastName = '#LastName#'
</CFIF>
<CFIF #FirstName# is not "">
AND FirstName LIKE '%#FirstName#%'
</CFIF>
</CFQUERY>
Tip: The WHERE 0=0 clause has no impact on the query submitted to the database. But if none of the conditions is true, it ensures that the WHERE clause does not result in a SQL syntax error.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998