CFLib.org – Common Function Library Project

columnTotal(qryColumn)

Last updated May 13, 2003

author

Scott Barber

Version: 2 | Requires: CF5 | Library: DataManipulationLib

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:

<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:

/**
 * 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 & ")")));
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson