While reading the CF-Talk e-mails, I noticed a couple of interesting, yet simple, facts about queries and totals in ColdFusion. First, in any query, queryName["columnName"] returns an array of columnName values. Second, if you want to calculate the sum of columnName values, you can simply use the function arraySum(). Here is an example (tested on CFMX7):
<cfset q = queryNew("col1", "integer")>
<cfset queryAddRow(q,4)>
<cfset querySetCell(q,"col1",1,1)>
<cfset querySetCell(q,"col1",2,2)>
<cfset querySetCell(q,"col1",3,3)>
<cfset querySetCell(q,"col1",4,4)>
<cfdump var="#q#">
<cfloop from="1"
to="#arrayLen(q['col1'])#"
index="i">
<cfoutput>
#i#
</cfoutput>
<br>
</cfloop>
<cfoutput>
#arraySum(q["col1"])#
</cfoutput>
(Thanks Deanna Schneider)
Possibly related:
- XML configuration files used in ColdFusion MX
- That Fine Code
- ColdFusion + AJAX = CFAjax
- Read XML from an HTTP POST
- Read The Fabulous Manual
Tagged query | Post a Comment


















Home > About This Post
This entry was posted by Eddie Awad on Friday, July 8th, 2005, at 11:17 am, and was filed in ColdFusion.
Subscribe to the
RSS 2.0 feed for all comments to this post.
Post a Comment