> Hey all,
> anyone know of an easy way to set values of
> form.fieldnames to null if they are blank
> I'm trying to do it so null values instead of blanks are sent
> to a storeproc.
> Any help would be appreciated.
> eg
> <cfloop index="field" LIST="#FORM.fieldnames#">
> <cfif Trim(evaluate(field)) eq "">
> <cfset formVariable = "null">
> </cfif>
> </cfloop>
Here's an alternate method for doing the same thing, when you use your
CFPROCPARAM or CFQUERYPARAM tags, courtesy of Dan Switzer:
"
I found a little tip that save me a few lines of code and thought I'd share
it. You may already be doing this, but a function I rarely use is the
YesNoFormat() function. However, I recently found a neat little place to use
it.
When passing a parameter into a stored procedure via the <CFPROCPARAM> tag,
you have the option to specify whether or not to pass a value or pass the
value as null. Using the YesNoFormat() you can now insert a value (if there
is one) or pass null is the string is blank. This is very useful for date
fields.
For example:
<CFPROCPARAM TYPE="In" CFSQLTYPE="CF_SQL_TIMESTAMP"
DBVARNAME="@ExpirationDate" VALUE="#ExpirationDate#" NULL="#YesNoFormat(NOT
Len(ExpirationDate))#">
This will insert the value in the field "ExpirationDate" as long as the
string isn't empty. If it's empty, the stored procedure will receive a null
value."
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.