What about ValueList() Function

Description

Inserts a delimiter between each value in an executed query. ColdFusion does not evaluate the arguments.

Return value

A delimited list of the values of each record returned from an executed query.

Syntax

ValueList(query.column [, delimiter ])

See also

QuotedValueList

Parameters

Parameter Description
query.column
Name of an executed query and column. Separate query name and column name with a period.
delimiter
A delimiter character to separate column data items.

http://livedocs.macromedia.com/coldfusion/6/CFML_Reference/functions-pt2115.htm

----- Original Message -----
From: Baz
Sent: Tuesday, November 08, 2005 4:19 PM
Subject: [CFCDev] Query: Turn column into a list

 

If I have the following query:

 

Column1 || Column2

  ValueA ||   ValueX

  ValueA ||   ValueY

  ValueB ||   ValueX

  ValueB ||   ValueY

  ValueB ||   ValueZ

 

 

And I want to turn the second column into a list, while keeping the first column unique - like so:

 

Column1 || Column2

  ValueA ||   ValueX, ValueY

  ValueB ||   ValueX, ValueY, ValueZ

 

 

Is there a more efficient way to do this than:

 

<cfoutput query="QueryXXX" group="Column1">

 

            <!--- populate groups list --->

            <cfoutput>

                        <cfset ColumnToList=listappend(ColumnToList,Column2) />

            </cfoutput>                   

 

            <!--- add row to final query --->

            <cfscript>

                        queryaddrow(FinalQuery);

                        querysetcell(FinalQuery,'Column1', Column1);

                        querysetcell(FinalQuery,'Column2', ColumnToList);

            </cfscript>

</cfoutput>

 

I’m sure there’s a million ways to do this…

 

Baz

 

 

 

 

 

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to