QueryReverse(qryOriginal)
Last updated June 27, 2002
Version: 1 | Requires: CF5 | Library: DataManipulationLib
Description:
Pass this function a query it will return a new one in reverse order (make first row the last and last row the first - in a new query).
Return Values:
Returns a query object.
Example:
<CFSET Foo = QueryNew("name,age,rank")>
<CFLOOP INDEX="X" FROM=1 TO=10>
<CFSET QueryAddRow(Foo)>
<CFSET QuerySetCell(Foo,"name","Random Name #X#")>
<CFSET QuerySetCell(Foo,"age",RandRange(20,50))>
<CFSET QuerySetCell(Foo,"rank",RandRange(1,10))>
</CFLOOP>
Original...<BR>
<CFDUMP VAR="#Foo#">
<P>
<CFSET Reverse = QueryReverse(Foo)>
Reverse...<BR>
<CFDUMP VAR="#Reverse#">
Parameters:
Name | Description | Required |
---|---|---|
qryOriginal | Name of the query you want to reverse | Yes |
Full UDF Source:
/**
* Reverse the order of a query.
*
* @param qryOriginal Name of the query you want to reverse (Required)
* @return Returns a query object.
* @author David Whiterod (whiterod.david@saugov.sa.gov.au)
* @version 1, June 27, 2002
*/
function QueryReverse (qryOriginal) {
// Reverse the order of qryOriginal
// Make a new query using the same columns as qryOriginal
var qryNew = QueryNew(qryOriginal.ColumnList);
var row = 1;
var column = 1;
//Loop through qryOriginal in reverse order (last becomes first)
for(row=qryOriginal.recordCount;row gte 1; row=row-1) {
//Add a new row in the new query
QueryAddRow(qryNew,1);
//Get the values for each column in qryOriginal
for(column=1;column lte ListLen(qryOriginal.ColumnList);column=column+1) {
QuerySetCell(qryNew, ListGetAt(qryOriginal.ColumnList,column), qryOriginal[ListGetAt(qryOriginal.ColumnList,column)][row]);
}
}
return qryNew;
}
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