Skip to main content
August 12, 2011
Answered

Real Data Type Empty

  • August 12, 2011
  • 1 reply
  • 304 views

Hi,

I'm ultimately trying to write a process to take data from an Apache Derby database and insert it into SQL Server 2008.  Everything has been working fine until I started working with the ows table FILMS, which has a numeric/real column of AMOUNTBUDGETED.  I'm running the following query to retrieve the data:

<cfquery name="getFilms" datasource="ows">

SELECT FILMID, MOVIETITLE, PITCHTEXT, AMOUNTBUDGETED, RATINGID, SUMMARY, IMAGENAME, DATEINTHEATERS

FROM FILMS

</cfquery>

If I <cfloop> through getFilms and use <cfoutput> to display AMOUNTBUDGETED, it displays the data.  However, when I actually go to insert AMOUNTBUDGETED into SQL Server it acts as if no value is being found for AMOUNTBUDGETED.  So, I ran the following test:

<cfloop query="getFilms">

<cfset budget = getFilms.AMOUNTBUDGETED>

<cfoutput>

#budget#<br/>

</cfoutput>

</cfloop>

This works fine and displays the field correctly.  However, if I run the following code, I get the following error:

<cfloop query="getFilms>

<cfset budget = getFilms.AMOUNTBUDGETED * 1.00>

</cfloop>

The value '' cannot be converted to a number.

The error occurred in C:\ColdFusion9\wwwroot\ows\Utilities\films.cfm: line 8

6 : 
7 : <cfloop query="getFilms">
8 :      <cfset budget = getFilms.AMOUNTBUDGETED * 1.00>
9 : </cfloop>
10 : 


If I use <cfoutput>, ColdFusion can find the value for AMOUNTBUDGETED, but if I try to do anything else it can't seem to find the value.  Needless to say, this is causing problems when I try to insert the value for AMOUNTBUDGETED into Sql Server.  Any suggestions would be appreciated.

Thanks.

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    Doing Your Own Bug Investigation 101:

    If you get an error you don't understand, put a try/catch around the line that's erroring and dump out the data that is used on that line.  This will generally reveal what's going wrong.

    In this case you'll see that getFilms.AMOUNTBUDGETED is null (as far as CF is concerned, an empty string).  One cannot perform multiplication on a string, empty or otherwise.

    --

    Adam

    1 reply

    Adam Cameron.Correct answer
    Inspiring
    August 12, 2011

    Doing Your Own Bug Investigation 101:

    If you get an error you don't understand, put a try/catch around the line that's erroring and dump out the data that is used on that line.  This will generally reveal what's going wrong.

    In this case you'll see that getFilms.AMOUNTBUDGETED is null (as far as CF is concerned, an empty string).  One cannot perform multiplication on a string, empty or otherwise.

    --

    Adam