Or actually, if the variable isn't even created you'll have to:

<cfif isDefined("Recordset2.Total")>
<cfoutput><cfset newTotal =(Recordset2.TOTAL - Recordset1.TOTAL)>#newTotal#
</cfoutput>
<cfelse>
Statements to deal with when the value is null
</cfif>

-----Original Message-----
From: Mark Smyth 
Sent: 07 August 2001 09:52
To: CF-Talk
Subject: RE: Subtract Null = Error


HI

Something like this should do it
Depending whether the variable is null or has a value cf will evaulate which
one to use automatically

<cfif Recordset2.Total is "NULL">
Statements to deal with when the value is null
<cfelse>
<cfoutput><cfset newTotal =(Recordset2.TOTAL - Recordset1.TOTAL)>#newTotal#
</cfoutput>
</cfif>


regards
Mark Smyth 
Macromedia Certified ColdFusion Developer 
Systems Union eBusiness Solutions 
00 44 1865 880800 

-----Original Message-----
From: Gryphawk [mailto:[EMAIL PROTECTED]]
Sent: 07 August 2001 09:41
To: CF-Talk
Subject: Subtract Null = Error


Hi there

I was hoping you could help me with a problem - I have a calculated value
from the following code:

<cfoutput><cfset newTotal =(Recordset2.TOTAL - Recordset1.TOTAL)>#newTotal#
</cfoutput>

Which works just fine when the Recordset2.TOTAL and Recordset1.TOTAL are
populated by the SQL (as set by search parameters on a previous page).  

However, on occasion Recordset2.Total is equal to nothing (null?) while
Recordset1.TOTAL has a value due to the search string, and when this
happens, CF throws an error which reads:

"An error occurred while evaluating the expression: 

  newTotal =(Recordset2.TOTAL - Recordset1.TOTAL)

 Error near line 316, column 17.

 Cannot convert to number."

Is there anyway to get around this such as an If Recordset.TOTAL = nothing,
Then [don't subtract]? 

My apologies that I am only just starting to learn how to write coded stuff.

Many thanks,

Gryphawk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to