CFLib.org – Common Function Library Project

getQueryColumns(theQuery)

Last updated January 12, 2011

author

James Moberg

Version: 1 | Requires: CF6 | Library: DatabaseLib

Description:
Retrieve a list of column names in the order as defined by SQL for use with CFSpreadsheet (generating a header row) and other loop functions.

Return Values:
Returns a list.

Example:

<cfquery name="GetOrders">
SELECT orderid, customerfirstname, customerlastname, total
FROM orders
ORDER BY orderid
</cfquery>

<CFSET ColumnList = getQueryColumns(GetOrders)>

Parameters:

Name Description Required
theQuery Query object to examine. Yes

Full UDF Source:

/**
 * Returns list of query columns in order as defined by SQL query.
 * 
 * @param theQuery      Query object to examine. (Required)
 * @return Returns a list. 
 * @author James Moberg (james@ssmedia.com) 
 * @version 1, January 11, 2011 
 */
function getQueryColumns(theQuery){
    if(isQuery(theQuery)) return arraytoList(theQuery.getMeta().getColumnLabels());
    else return '';
}

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