Copy link to clipboard
Copied
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:
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.
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
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Found it after scrolling.
Just realized that the reason why I could not find was that I had my 'match case' enabled in firefox's find, thus 'val' was not 'Val'.
Thank you.