If one of the columns in the returned coldfusion query result set has a NULL, how do we check if the value of this column being NULL?
Should we just say <cfif queryname.columnname[i] EQ ''>
OR <cfif queryname.columnname[i] eq 'NULL'>
?
If one of the columns in the returned coldfusion query result set has a NULL, how do we check if the value of this column being NULL?
Should we just say <cfif queryname.columnname[i] EQ ''>
OR <cfif queryname.columnname[i] eq 'NULL'>
?
Null value will only be returned as empty string in a query object.
Ideally, you would use your database's ifnull
(or similar) method to convert null values to something appropriate before they reach CF.
If not, they come back as an empty string, so your first cfif
is correct.
If you are using an oracle database you could use the NVL method and modify your query to wrap the column.
<cfset var nullstringvalue = "THELASTNAMEFIELDISNULL" />
<cfquery name="lastnamelookup" ....>
SELECT NVL(lastname, 'LASTNAMEISNULL') AS lastname
</cfquery>
<cfif lastnamelookup.lastname EQ nullstringvalue>
...do null case work...
</cfif>
The trick would be in determining the correct bogus string to use in this case, then testing for it.