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
Tayo Akinmade added
arrayTrim
10 day(s) ago
Will Belden added
longTime
15 day(s) ago
James Sleeman added
quickSort
25 day(s) ago
Ben Forta added
GetHostAddress
28 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)