NullColumn(columnValue [, dataType])
Last updated September 20, 2002
Version: 1 | Requires: ColdFusion 5 | Library: DatabaseLib
Description:
This function takes a CF variable and optionally a CF datatype ('alpha' or 'numeric') and returns either the CF value or NULL. If it returns the CF value, it will be quoted if invoked with the 'alpha' datatype argument (default).
Return Values:
Returns a string.
Example:
<cfset testFld1 = "a">
update test<br>
set testfld = #nullColumn(testFld1)#<br>
where keycol = 2<br><br>
<cfset testFld2 = "">
update test<br>
set testfld = #nullColumn(testFld2)#<br>
where keycol = 2<br><br>
<cfset testFld3 = 9>
update test<br>
set testNumeric = #nullColumn(testFld3, 'numeric')#<br>
where keycol = 2<br><br>
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| columnValue | The value to test. | Yes |
| dataType | Allows you to specify 'alpha' or 'numeric'. If alpha, value is wrapped in single quotes. Default is alpha. | No |
Full UDF Source:
<cfscript>
/**
* Useful in constructing SQL statements that must handle empty strings as NULLs.
* Rewritten to use one UDF by RCamden
*
* @param columnValue The value to test. (Required)
* @param dataType Allows you to specify 'alpha' or 'numeric'. If alpha, value is wrapped in single quotes. Default is alpha. (Optional)
* @return Returns a string.
* @author Charles McElwee (cmcelwee@etechsolutions.com)
* @version 1, September 20, 2002
*/
function NullColumn(columnValue) {
var dataType = "alpha";
if(arrayLen(arguments) gte 2) dataType = arguments[2];
if(trim(columnValue) eq "") return "NULL";
else if(dataType is "alpha") return "'" & columnValue & "'";
else return columnValue;
}
</cfscript>
Search CFLib.org
Latest Additions
Jose Diaz-Salcedo added
cfRssFeed
2 day(s) ago
Raymond Compton added
structBlend
23 day(s) ago
Duncan added
IsZIPUK
23 day(s) ago
Todd Sharp added
getTagContentAll
29 day(s) ago
Gerald Guido added
ListReturnDuplicat...
1 month(s) ago