Skip to content

Instantly share code, notes, and snippets.

@johnbocook
Last active November 5, 2015 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbocook/6b00c09849ef60f8dfc7 to your computer and use it in GitHub Desktop.
Save johnbocook/6b00c09849ef60f8dfc7 to your computer and use it in GitHub Desktop.
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.
<cfscript>
function getQueryColumns(theQuery){
if(isQuery(theQuery)) return arraytoList(theQuery.getMeta().getColumnLabels());
else return '';
}
</cfscript>
<!--- Example --->
<cfquery name="GetOrders">
SELECT orderid, customerfirstname, customerlastname, total
FROM orders
ORDER BY orderid
</cfquery>
<cfset ColumnList = getQueryColumns(GetOrders)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment