Wednesday, August 26, 2009

Function to Calculate sum of a query colmn

I wrote a query which had a decimal column in it. i used to create a temporary field and loop over the query and find the total sum. I felt coldfusion should have function to directly get this value. As far as i know i don't think there is a single function which i can use to do this.

so i tried
arraysum(myquery.amount)

since myquery.amount is actually myquery.amount[currentrow] it dint work

so i tried
arraysum(valuelist(myquery.amount))

since its a list not an array i got error message
and finally i converted it to array and calculated the sum.
Here is my final expression

dollarformat(arraysum(listtoarray(valuelist(myquery.amount))))

No comments:

Blog Archive