AdobeStock_455007340

Truly Dynamic SQL

All ColdFusion developers know that CF variables may be used in SQL statements, and most have used them in WHERE clauses as well as in INSERT and UPDATE statements. But what many developers do not know is that any part of the SQL string may be created using variables, in fact, the entire SQL statement may in fact be a variable. Want to allow users to select data sort order? Simply let them make a selection and use that in the ORDER BY clause. Joining multiple tables that perhaps need not always be joined (perhaps based on dynamic WHERE clauses? Simply include tables in the FROM clause dynamically. Remember, a SQL statement is simply a string, and as such may be constructed using variables and expressions however needed. (Applies to: ColdFusion All)

Leave a Reply