我想汇总我的决赛桌,但不知道如何解决加入部分。我有一个 Do While 循环,它通过我的表contracts.dbf 将每一行传递到一个过程中。此过程 test33 使用此信息并从其他表中挑选出所需的数据。我想要的聚合是每个循环的所有结果,所以如果contracts.dbf 中有101 行,那么joining.dbf 将是101 列宽。
DELETE FILES *.tmp RECYCLE
SELECT distinct depot_nr FROM bs_case;
INTO table contracts.tmp
SELECT RECNO() as rownum,;
depot_nr as depot_nr;
FROM contracts.tmp
NbContracts =RECCOUNT()
COPY TO test3.dbf
CLOSE TABLES
counter = 1
DO WHILE counter < NbContracts
SELECT depot_nr as depot_nr;
WHERE rownum = counter FROM test3
test33(depot_nr, counter)
counter = counter + 1
ENDDO
CLOSE TABLES
PROCEDURE test33(depot_nr_in, NbofTimes)
use bs_case alias bs
SELECT Depot_nr as depot_nr,;
Psres3pcgb as psres3pcgb;
WHERE Depot_nr = depot_nr_in FROM bs INTO TABLE toJoin.tmp
DO CASE
CASE NbofTimes = 1
SELECT * FROM toJoin.tmp
COPY TO joining.dbf
CASE NbofTimes = NbContracts
?counter
SELECT * FROM bsP.tmp as one LEFT JOIN joining.dbf as aggregated; && ERROR HERE
ON (one.depot_nr = aggregated.depot_nr) into table joining.dbf
CLOSE TABLES
ENDPROC
Otherwise
SELECT * FROM toJoin.tmp as one LEFT JOIN joining.dbf as aggregated; && ERROR HERE
ON (one.depot_nr = aggregated.depot_nr) into table joining.dbf
CLOSE TABLES
ENDCASE
CLOSE TABLES
CLOSE DATABASES
ENDPROC
数据看起来像
bs_case
===================================
depot_nr Psres3pcgb
22 123
31 222
22 345
32 444
23 222
22 222
contracts.dbf
===================================
22
31
32
23
我的过程将contracts.dbf 中的每个值作为参数。这是通过 do while 循环完成的。
我希望最终结果是每次运行 test33 过程的表格。例如
Loop 1
===============
22
the result
Loop2
==============
22 31
test33(22) test33(31)
Loop3
==============
22 31 32
test33(22) test33(31) test33(32)
Loop4
==============
22 31 32 23
test33(22) test33(31) test33(32) test33(23)
test33(##) 的每个结果都是一列值。我希望这可以更好地了解我要做的事情