CFLib.org – Common Function Library Project

QueryDeleteRows(Query, Rows)

Last updated October 11, 2001

author

Raymond Camden

Version: 2 | Requires: CF5 | Library: DataManipulationLib

Description:
This function will allow you to remove rows from a query. You can either remove one row or a list of rows.

Return Values:
This function returns a query.

Example:

<CFSET Query = QueryNew("id,name,age")>
<CFLOOP INDEX="X" FROM=1 TO=8>
<CFSET QueryAddRow(Query,1)>
<CFSET QuerySetCell(Query,"ID",X,X)>
<CFSET QuerySetCell(Query,"Name","Name #X#",X)>
<CFSET QuerySetCell(Query,"Age",X+15,X)>
</CFLOOP>
Before deleting<BR>
<CFDUMP VAR="#Query#">
<CFSET Query = QueryDeleteRows(Query,"1,3")>
<P>After removing rows 1 and 3<BR>
<CFDUMP VAR="#Query#">
<P>After removing row 3<BR>
<CFSET Query = QueryDeleteRows(Query,3)>
<CFDUMP VAR="#Query#">

Parameters:

Name Description Required
Query Query to be modified Yes
Rows Either a number or a list of numbers Yes

Full UDF Source:

/**
 * Removes rows from a query.
 * Added var col = "";
 * No longer using Evaluate. Function is MUCH smaller now.
 * 
 * @param Query 	 Query to be modified 
 * @param Rows 	 Either a number or a list of numbers 
 * @return This function returns a query. 
 * @author Raymond Camden (ray@camdenfamily.com) 
 * @version 2, October 11, 2001 
 */
function QueryDeleteRows(Query,Rows) {
	var tmp = QueryNew(Query.ColumnList);
	var i = 1;
	var x = 1;

	for(i=1;i lte Query.recordCount; i=i+1) {
		if(not ListFind(Rows,i)) {
			QueryAddRow(tmp,1);
			for(x=1;x lte ListLen(tmp.ColumnList);x=x+1) {
				QuerySetCell(tmp, ListGetAt(tmp.ColumnList,x), query[ListGetAt(tmp.ColumnList,x)][i]);
			}
		}
	}
	return tmp;
}
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