CFLib.org – Common Function Library Project

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

Last updated September 09, 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>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson