CFLib.org – Common Function Library Project

listToQuery(list[, delimiters][, column_name])

Last updated September 9, 2009

author

Russ Spivey

Version: 0 | Requires: CF6 | Library: DataManipulationLib

Description:
Converts a list to a single-column query.

Return Values:
Returns a query.

Example:

<cfset my_list = 'one,two'>
<cfset my_query = listToQuery(my_list)>
<cfdump var="#my_query#">

Parameters:

Name Description Required
list List of items. Yes
delimiters List delimiters. Defaults to a comma. No
column_name Name to use for column. Defaults to column. No

Full UDF Source:

<!---
 Converts a list to a single-column query.
 
 @param list 	 List of items. (Required)
 @param delimiters 	 List delimiters. Defaults to a comma. (Optional)
 @param column_name 	 Name to use for column. Defaults to column. (Optional)
 @return Returns a query. 
 @author Russ Spivey (russellspivey@gmail.com) 
 @version 0, September 9, 2009 
--->
<cffunction name="listToQuery" access="public" returntype="query" output="false" 
	hint="Converts a list to a single-column query.">
    <cfargument name="list" type="string" required="yes" hint="List to convert.">
    <cfargument name="delimiters" type="string" required="no" default="," hint="Things that separate list elements.">
    <cfargument name="column_name" type="string" required="no" default="column" hint="Name to give query column.">
    
    <cfset var query = queryNew(arguments.column_name)>
    <cfset var index = ''>
    
    <cfloop list="#arguments.list#" index="index" delimiters="#arguments.delimiters#">
        <cfset queryAddRow(query)>
        <cfset querySetCell(query,arguments.column_name,index)>
    </cfloop>
    
    <cfreturn query>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson