Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How to convert Query column to a list in ColdFusion

Writer Andrew Henderson

I'm trying to convert ColdFusion query column to a list, what is the best way to do so?

I thought that there is a built in function that allows one to easily convert a query's column in to a list, if there is what is it?

1

3 Answers

There is a built-in function to do that: ValueList

<cfset myList = ValueList(query.columnname)>

As with all of the list functions, there's an optional delimiter attribute.

<cfset myList = ValueList(query.columnname,"|")>

If you need the values in the list to have double-quotes around them, use QuotedValueList.

<cfset myList = QuotedValueList(query.columnname)>
2

You can also access a query's columns as arrays directly without any conversion if that works for what you're trying to do:

qry.col[1] // col field of first record
qry.col[2] // col field of second record
...

or

qry["col"][1] // col field of first record
qry["col"][2] // col field of second record

A CF query object is really an associative array of columns... weird but occasionally useful.

8

How about in a case like this:

<cfset SummaryQuery = Evaluate('getReportData' & summaryName & 'Summary') />
<cfset TypeList = ArrayToList(SummaryQuery[subsectionName & 'Type']) />

vs.

<cfset QueryColumn = SummaryQuery[subsectionName & 'Type'] />
<cfset TypeList = ValueList(QueryColumn) />

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.