CFLib.org – Common Function Library Project

queryColumnToList(qry, column[, delim])

Last updated January 4, 2007

author

Randy Johnson

Version: 1 | Requires: CF5 | Library: StrLib

Description:
The function was inspired by the queryColumnToArray. It takes a query and a column as arguments and returns a list.

Return Values:
Returns a list.

Example:

<cfset qry = QueryNew("Column1,Column2") />
<cfset queryAddRow(qry)>
<cfset QuerySetCell(qry,"Column1", "A") />
<cfset QuerySetCell(qry,"Column2", "A1") />
<cfset queryAddRow(qry)>
<cfset QuerySetCell(qry,"Column1", "B") />
<cfset QuerySetCell(qry,"Column2", "B2") />
<cfset queryAddRow(qry)>
<cfset QuerySetCell(qry,"Column1", "C") />
<cfset QuerySetCell(qry,"Column2", "C3") />

<cfset theList = queryColumnToList(qry, "Column1") />
<cfdump var="#theList#" />

Parameters:

Name Description Required
qry Query to use. Yes
column Column to use. Yes
delim Delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * Takes a selected column of data from a query and converts it into a list.
 * 
 * @param qry 	 Query to use. (Required)
 * @param column 	 Column to use. (Required)
 * @param delim 	 Delimiter. Defaults to a comma. (Optional)
 * @return Returns a list. 
 * @author Randy Johnson (randy@cfedge.com) 
 * @version 1, January 4, 2007 
 */
function queryColumnToList(qry, column) {
	var theList = "";
	var counter = "";
	var num_rows = arguments.qry.recordcount;
	var delim = ",";
	if(arrayLen(arguments) gte 3) delim = arguments[3];
	for (counter=1; counter lte num_rows; counter=counter+1) theList = listAppend(theList, arguments.qry[arguments.column][counter],delim);
	return theList;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson