July 25, 2009 - 3:22 AM (GMT)
Category: Coldfusion,tech notes
I was recently adding some features to my CMS system and came accross a feature of cfqueryparam that I had not used in a while but is really nice when you need it. When doing an insert or update query for an integer field you can specify the Null attribute of the cfqueryparam tag.
Here is an example:
<cfqueryparam cfsqltype="cf_sql_integer" value="#form.duration#" NULL="#NOT len(form.duration)#">
So what this is doing is testing if there is any value in the form.duration field, and if there is nothing there, insert a NULL. If there is something there is just inserts the field value normally.