How to check for a null value from the return value in ColdFusion query loop

Evlikosh Dawark picture Evlikosh Dawark · Feb 9, 2012 · Viewed 45.4k times · Source
<cfloop query="GET_ALL_STUDENTS>
 <cfif #student_id# is  NOT NULL>
 <!--- do something--->
 </cfif>
</cfloop>   

Above is how I am looping my cf query which returns null value and I want to check if the student_id is null or not. This is what I have tried and it failed. Can anyone tell me a better way?

Answer

Billy Cravens picture Billy Cravens · Feb 9, 2012

You can use your database's ifNull() or the like. However, in ColdFusion, queries are returned as strings. Given your situation, easiest way is to check for a non-empty string:

<cfif len(student_id)>

By the way, you don't need the pound signs inside of an evaluation: only when using a variable as a literal (such as when outputting)