Skip to main content
Known Participant
September 14, 2010
Answered

The value coldfusion.sql.QueryTable cannot be converted to a number

  • September 14, 2010
  • 2 replies
  • 3316 views

Hi,

I have two queries, in two different functions, which both return the SUM of a column, depending on the values from the arguments

I need to subtract query 2 from query 1.

The arguments for both queries are passed using the CreateObject Function

<cfset qry1 = createObject("component","components.adminobjects").Func1(#argument1#,#argument2#)>

<cfset qry2 =  createObject("component","components.adminobjects").Func1(#argument1#,#argument2#)>

The queries do get executed accordingly and returns the results accordingly.

The problem occurs when I try to calculate by subtracting the 2nd query form the 1st.

So, to get the results that I need, this is what I do:

<cfset results = "#qry1.sum#" - "#qry1.sum2#">

<cfoutput>#results#</cfoutput>

When I do this, it says:

The  value coldfusion.sql.QueryTable cannot be converted to a number

I do not get it, this is because when I output #qry1.sum# or #qry1.sum2# I do get the right figures and they are numbers, but when I do some math on them, I get the error.

Any ideas?

Thank you.

    This topic has been closed for replies.
    Correct answer JR__Bob__Dobbs

    Assuming that the qry1 object has a columns named "sum1" and "sum2"  try :

    <cfset results = Val(qry1.sum1) - Val(qry1.sum2)>

    Also note that "sum" is a reserved word, try changing the column "sum" to "sum1".

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec173d0-7fff.html

    2 replies

    JR__Bob__DobbsCorrect answer
    Inspiring
    September 14, 2010

    Assuming that the qry1 object has a columns named "sum1" and "sum2"  try :

    <cfset results = Val(qry1.sum1) - Val(qry1.sum2)>

    Also note that "sum" is a reserved word, try changing the column "sum" to "sum1".

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec173d0-7fff.html

    n_kipAuthor
    Known Participant
    September 14, 2010

    Thank Bob,

    I did both and it worked.

    I looked for the Val function in the main function list in CF 8's Documentation, but did not find it. Shouldn't it be there? To find it, you'd first have to go to the "Conversion Functions".

    I've just learnt a new function.

    Thanks again.

    Inspiring
    September 14, 2010

    The function is listed in the online CF8 documentation on the page linked below.

    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_01.html

    n_kipAuthor
    Known Participant
    September 14, 2010

    Just want correct something

    <cfset qry2 =   createObject("component","components.adminobjects").Func1(#argument1#  ,#argument2#)>

    goes to Func2 not to Func1. (I copied and pasted & forgot to edit that)