Queryappend 的任何自定义函数
Any custom function for Queryappend
Queryappend 在 Coldfusion - 18 中而不在 Coldfusion - 16 中。
任何人都可以为“Queryappend”推荐任何自定义 coldfusoin 函数吗
假设我有 2 个查询:
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
提前致谢
这是实现此目的的一种方法。
<cfscript>
IDList1 = '1,2,3';
IDList2 = '6,5,4';
NameList1 = 'Fred,Wilma,Pebbles';
NameList2 = 'Barney,Betty,Bam,Bam';
Flinstones = QueryNew("UserID,UserName", 'integer,varchar');
Rubbles = QueryNew("UserID,UserName", 'integer,varchar');
for (i = 1; i <=3; i++) {
QueryAddRow(Flinstones);
QuerySetCell(Flinstones, 'UserID', i);
QuerySetCell(Flinstones, 'UserName'
, ListGetAt(NameList1, i));
QueryAddRow(Rubbles);
QuerySetCell(Rubbles, 'UserID'
, ListGetAt(IDList2, i));
QuerySetCell(Rubbles, 'UserName'
, ListGetAt(NameList2, i));
}
</cfscript>
<cfquery name="All" dbtype="query">
select UserID, UserName
from Flinstones
order by UserID
</cfquery>
<cfloop query = "Rubbles">
<cfset QueryAddRow(All)>
<cfset QuerySetCell(All, 'UserId', UserId,
All.recordcount)>
<cfset QuerySetCell(All, 'UserName', UserName,
All.recordcount)>
</cfloop>
<cfdump var="#all#">
你可以玩玩它here。
将此逻辑放入接受两个查询和 returns 第三个查询的函数中并不难。
在早期版本的 ColdFusion 中模拟 queryAppend()
的最简单且最易读的解决方案是使用查询查询 (qoq
),然后使用 union all
功能追加结果 qoq
通过不提供 ORDER BY
子句。
<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>
这是要点的工作示例 https://trycf.com/gist/484d3ab19f52d81867dacdced47fad09/lucee5?theme=monokai
Queryappend 在 Coldfusion - 18 中而不在 Coldfusion - 16 中。
任何人都可以为“Queryappend”推荐任何自定义 coldfusoin 函数吗
假设我有 2 个查询:
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
提前致谢
这是实现此目的的一种方法。
<cfscript>
IDList1 = '1,2,3';
IDList2 = '6,5,4';
NameList1 = 'Fred,Wilma,Pebbles';
NameList2 = 'Barney,Betty,Bam,Bam';
Flinstones = QueryNew("UserID,UserName", 'integer,varchar');
Rubbles = QueryNew("UserID,UserName", 'integer,varchar');
for (i = 1; i <=3; i++) {
QueryAddRow(Flinstones);
QuerySetCell(Flinstones, 'UserID', i);
QuerySetCell(Flinstones, 'UserName'
, ListGetAt(NameList1, i));
QueryAddRow(Rubbles);
QuerySetCell(Rubbles, 'UserID'
, ListGetAt(IDList2, i));
QuerySetCell(Rubbles, 'UserName'
, ListGetAt(NameList2, i));
}
</cfscript>
<cfquery name="All" dbtype="query">
select UserID, UserName
from Flinstones
order by UserID
</cfquery>
<cfloop query = "Rubbles">
<cfset QueryAddRow(All)>
<cfset QuerySetCell(All, 'UserId', UserId,
All.recordcount)>
<cfset QuerySetCell(All, 'UserName', UserName,
All.recordcount)>
</cfloop>
<cfdump var="#all#">
你可以玩玩它here。
将此逻辑放入接受两个查询和 returns 第三个查询的函数中并不难。
在早期版本的 ColdFusion 中模拟 queryAppend()
的最简单且最易读的解决方案是使用查询查询 (qoq
),然后使用 union all
功能追加结果 qoq
通过不提供 ORDER BY
子句。
<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>
这是要点的工作示例 https://trycf.com/gist/484d3ab19f52d81867dacdced47fad09/lucee5?theme=monokai