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. |