CFLib.org – Common Function Library Project

columnTotal(qryColumn)

Last updated May 13, 2003

Version: 2 | Requires: ColdFusion 5 | Library: DataManipulationLib

 
Rated 1 time(s). Average Rating: 4.0

Description:
With this UDF, you can get the total of all rows for any given query column. Assuming of course that the column you specify contains numbers! :-)

Return Values:
Returns a number.

Example:

view plain print about
<cfset foo = queryNew("total")>
<cfset queryAddRow(foo,10)>

<cfloop index="x" from=1 to=10>
    <cfset querySetCell(foo,"total",x,x)>
</cfloop>

<cfoutput>#columnTotal("foo.total")#</cfoutput>

Parameters:

Name Description Required
qryColumn The name and column of the query, i.e. foo.total Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * This UDF calculates the total of a column from a query.
 * Version 2 by Raymond Camden
 * 
 * @param qryColumn      The name and column of the query, i.e. foo.total (Required)
 * @return Returns a number. 
 * @author Scott Barber (charlesbarber@hotmail.com) 
 * @version 2, May 13, 2003 
 */

function columnTotal(qryColumn){
    return arraySum(listToArray(evaluate("valueList(" & qryColumn & ")")));
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson