How do I get the values from one column in a query?
If you need to retrieve the values from one column in a query, ColdFusion provides the valueList() function. It will return every value from that column. Here is an example:
select name, age, rank
from people
</cfquery>
<cfset allNames = valueList(getPeople.name)>
Note that valueList does not take a string, but the actual query and column variable.
This question was written by Raymond Camden.
It was last updated on March 23, 2006 at 6:55:54 AM EST.
CFML Referenced
Categories
Comments
Comment made by Sam Farmer on March 23, 2006 at 8:27 AM
Its worth pointing out; 1) That valueList also has an optional delimiter argument if you want the list to come back with something other than a comma: valueList(getPeople.name,".") would return names in a list of dots.
2) The function QuotedValueList will return each value in quotes. Quite useful if your values may contain commas, etc. It also takes a optional delimter (default a comma). QuotedValueList(getPeople.name) would return: "Ray","Ben","Sam"
Comment made by Sam Farmer on March 23, 2006 at 8:28 AM
A better example for QuotedValueList say name returned lastName, firstName So: QuotedValueList(getPeople.name) would return: "Camden, Ray","Forta, Ben","Farmer, Sam"
Comment made by Michael White on May 9, 2006 at 2:18 PM
this works Great for Emailing to a list of people, Thanks!