– Common Function Library Project

ColumnLoop(query, columnName, theEval)

Last updated September 12, 2003


Shawn Seley

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Applies the passed evaluation to every cell in the specified query column. Allows versatile conversions, calculations, formatting and other alterations to an entire query column in one step. Use the variable "x" in the passed evaluation to denote the cell's original value. Especially useful for pre-processing a query before passing it to <cfchart>.

Return Values:
Returns a query.


<CFSET my_query = QueryNew("URL,Hits")>
<CFSET QueryAddRow(my_query, 1)>
<CFSET QuerySetCell(my_query,"URL", "")>
<CFSET QuerySetCell(my_query,"Hits","1000")>
<CFSET QueryAddRow(my_query, 1)>
<CFSET QuerySetCell(my_query,"URL", "")>
<CFSET QuerySetCell(my_query,"Hits","100")>
<CFSET QueryAddRow(my_query, 1)>
<CFSET QuerySetCell(my_query,"URL", "")>
<CFSET QuerySetCell(my_query,"Hits","200")>

<CFDUMP VAR="#my_query#">

Modify with ColumnLoop("my_query", "Url", "x=ReplaceNoCase(x, """", """", ""ALL"")"):<br>
<cfset my_query2 = ColumnLoop(duplicate(my_query), "Url", "x=ReplaceNoCase(x, """", """", ""ALL"")")>
<CFDUMP VAR="#my_query2#">


Name Description Required
query Query object. Yes
columnName Column to be modified. Yes
theEval Evaluation to be performed. Use X to represent column data. Yes

Full UDF Source:

 * Applies simple evaluations to every cell in a query column.
 * @param query 	 Query object. (Required)
 * @param columnName 	 Column to be modified. (Required)
 * @param theEval 	 Evaluation to be performed. Use X to represent column data. (Required)
 * @return Returns a query. 
 * @author Shawn Seley ( 
 * @version 1, September 12, 2003 
function ColumnLoop(query, columnName, theEval) {
	var row = 0;
	var x = "";
	var rec_count = query.recordCount;
	for(row=1; row LTE rec_count; row=row+1) {
		x = query[columnName][row];
	return query;
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson