Warm tip: This article is reproduced from serverfault.com, please click

Any custom function for Queryappend

发布于 2020-12-10 11:13:30

Queryappend is in Coldfusion - 18 and not in Coldfusion - 16.

Can anyone suggest any custom coldfusoin function for "Queryappend"

Suppose I have 2 queries :

Query-1
select * from user where userid > 10 order by userid asc

Query-2
select * from user where userid < 10 order by userid desc

Query append should return folowing:

userid username 
11  AA
12  BB
13  CC
9   MM
8   NN
7   OO

Thanks in advance

Questioner
Ritu
Viewed
0
user12031119 2020-12-11 10:27:18

The easiest and most readable solution to emulate a queryAppend() in earlier versions of ColdFusion is by using a query of queries (qoq) and then using the union all feature to append the resultant qoq by not supplying an ORDER BY clause.

<cfquery name="query1" datasource="mydatasource">
    select * from user where userid > 10 order by userid asc
</cfquery>

<cfquery name="query2" datasource="mydatasource">
    select * from user where userid < 10 order by userid desc
</cfquery>

<!--- "Union all" the 2 result sets together in a qoq and don't supply an order by clause  --->
<cfquery name="queryAppend" dbtype="query">
    select * from query1
    union all
    select * from query2
</cfquery>

Here's a working sample of the gist https://trycf.com/gist/484d3ab19f52d81867dacdced47fad09/lucee5?theme=monokai