CFLib.org – Common Function Library Project

queryRemoveColumns(theQuery, columnsToRemove)

Last updated March 1, 2005

author

Giampaolo Bellavite

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Remove a list of columns from a specified query, using a query of query.

Return Values:
Returns a query.

Example:

<cfset aQuery=QueryNew('first_column,second_column,third_column,fourth_column')>
<cfset QueryAddRow(aQuery,1)>
<cfset QuerySetCell(aQuery,'first_column',1)>
<cfset QuerySetCell(aQuery,'second_column',2)>
<cfset QuerySetCell(aQuery,'third_column',3)>
<cfset QuerySetCell(aQuery,'fourth_column',4)>

<cfdump var="#aQuery#">	
<cfdump var="#queryRemoveColumns(aQuery,'second_column,third_column')#">

Parameters:

Name Description Required
theQuery The query to manipulate. Yes
columnsToRemove A list of columns to remove. Yes

Full UDF Source:

<!---
 Remove a list of columns from a specified query.
 
 @param theQuery 	 The query to manipulate. (Required)
 @param columnsToRemove 	 A list of columns to remove. (Required)
 @return Returns a query. 
 @author Giampaolo Bellavite (giampaolo@bellavite.com) 
 @version 1, April 14, 2005 
--->
<cffunction name="queryRemoveColumns" output="false" returntype="query">
	<cfargument name="theQuery" type="query" required="yes">
	<cfargument name="columnsToRemove" type="string" required="yes">
	<cfset var columnList=theQuery.columnList>
	<cfset var columnPosition="">
	<cfset var c="">
	<cfset var newQuery="">
	<cfloop list="#arguments.columnsToRemove#" index="c">
		<cfset columnPosition=ListFindNoCase(columnList,c)>
		<cfif columnPosition NEQ 0>
			<cfset columnList=ListDeleteAt(columnList,columnPosition)>
		</cfif>
	</cfloop>
	<cfquery name="newQuery" dbtype="query">
		SELECT #columnList# FROM theQuery
	</cfquery>
	<cfreturn newQuery>
</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