CFLib.org – Common Function Library Project

queryConcat([q1] [, q2])

Last updated February 23, 2006

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

 
Rated 1 time(s). Average Rating: 4.0

Description:
Appends queryTwo to queryOne. Sorting is ignored - queryTwo is appended to the end of queryOne. Note that both queries must have the same columns.

Return Values:
Returns a query.

Example:

view plain print about
cols = "sName,sAge";
heads = "First Name,Age";

q1 = queryNew(cols);
queryAddRow(q1,2);
querySetCell(q1,"sName","Joe",1);
querySetCell(q1,"sAge","25",1);
querySetCell(q1,"sName","John",2);
querySetCell(q1,"sAge","30",2);

q2 = queryNew(cols);
queryAddRow(q2,2);
querySetCell(q2,"sName","Kassi",1);
querySetCell(q2,"sAge","19",1);
querySetCell(q2,"sName","Mary",2);
querySetCell(q2,"sAge","20",2);
</cfscript>

<cfdump var="#q1#">
<cfdump var="#q2#">
<br><br>
Resulting query
<br>
<cfset resultQuery = queryConcat(q1, q2)>
<cfdump var="#resultQuery#">

Parameters:

Name Description Required
q1 First query. No
q2 Second query. No

Full UDF Source:

view plain print about
<cfscript>
/**
 * Concatenate two queries together.
 * 
 * @param q1      First query. (Optional)
 * @param q2      Second query. (Optional)
 * @return Returns a query. 
 * @author Chris Dary (umbrae@gmail.com) 
 * @version 1, February 23, 2006 
 */

function queryConcat(q1,q2) {
    var row = "";
    var col = "";

    if(q1.columnList NEQ q2.columnList) {
        return q1;
    }

    for(row=1; row LTE q2.recordCount; row=row+1) {
     queryAddRow(q1);
     for(col=1; col LTE listLen(q1.columnList); col=col+1)
        querySetCell(q1,ListGetAt(q1.columnList,col), q2[ListGetAt(q1.columnList,col)][row]);
    }
    return q1;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Adam Cameron Adam Cameron added
savecontent
25 day(s) ago

Pete Ruckelshaus Pete Ruckelshaus added
firstDayOfWeek
a while ago

Chris Weller Chris Weller added
convertQueryStri...
a while ago

Dan Bracuk Dan Bracuk added
getExcelPercenti...
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 42 time(s)

Barney Boisvert indentXml
Rated 5.0, 12 time(s)

Rachel Lehman deAccent
Rated 5.0, 8 time(s)

Markus Schneebeli                                 ListRemoveByStri...
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson