CFLib.org – Common Function Library Project

QueryDeleteRows(Query, Rows)

Last updated October 11, 2001
Download UDF

author

Raymond Camden                                    Raymond Camden

Version: 2 | Requires: ColdFusion 5 | Library: DataManipulationLib

 
Rated 1 time(s). Average Rating: 4.0

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:

<cfscript>
/**
* 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;
}
</cfscript>

Search CFLib.org


Latest Additions

Shawn Porter Shawn Porter added
DeMoronize
3 hour(s) ago

Chris Carey Chris Carey added
readPropertiesFi...
1 day(s) ago

Randy Johnson Randy Johnson added
lastDayofWeek
3 day(s) ago

Frank Marion Frank Marion added
sitemapPing
7 day(s) ago

Top Rated

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Barney Boisvert indentXml
Rated 5.0, 3 time(s)

Nathan Dintenfass                                 queryColumnsToSt...
Rated 5.0, 3 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson