Link to home
Start Free TrialLog in
Avatar of ssdanish
ssdanish

asked on

CFLoop error

I'm trying to calculate a sum in the following ColdFusion document.  When I do this sum with a dollar value, it works, and when I leave out the sum (just do line-by-line detail), it works.  When I try to run the following document, I get this error:  'The value "" cannot be converted to a number'


<cfquery name="campaign07" datasource="Pluto" dbtype="ODBC">
SELECT     ORGNAME1 AS Name, LDR_ORG_2006_UWSVANNUALCA_NBROFLEADERS_ALLLEADERS AS LdrN06
FROM         dbo.DATAEXTRACTANDARCAMPAIGN2006S
</cfquery>

<cfheader name="Content-Disposition" value="inline;filename=CampaignUpdate.xls">
<cfcontent type="application/msexcel">

<Table border="1" cellspacing="1">

<thead>
<tr>
<td>Name</td>
<td>LdrN06</td>
</tr>
</thead>

<cfset MyLdrN06 = 0>

<tbody>
<cfoutput query="campaign07">
<tr>
<td>#Name#</td>
<td>#NumberFormat(LdrN06,"99,999,999")#</td>
</tr>

<cfset MyLdrN06 = MyLdrN06 + LdrN06>
      
</cfoutput>
</tbody>

<tfoot>
<cfoutput>
<tr>
<td>TOTALS</td>
    <td>#NumberFormat(MyLdrN06,"99,999,999")#</td>
</tr>
</cfoutput>
</tfoot>

</table>
Avatar of _agx_
_agx_
Flag of United States of America image

> 'The value "" cannot be converted to a number'

That means you're trying to use a string "" where a number is expected.  I don't know which line is throwing the error, but try using the Val() function.  It will convert non-numeric values like ""  to 0.  

<cfset MyLdrN06 = MyLdrN06 + val(LdrN06)>
Avatar of ssdanish
ssdanish

ASKER

great; that worked; thanks
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial