我想彙總我的最終表並不知道如何解決加入部分。我有一個Do While循環通過我的表contracts.dbf,它將每行傳遞給一個過程。此過程test33使用此信息並從其他表中選取所需的數據。我期望的聚合是每個循環的所有結果,所以如果在contracts.dbf中有101行,那麼joining.dbf將是101列寬。FoxPro 9.0加入彙總表
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取的每個值作爲參數。這是通過while 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(##)的每個結果都是一列值。我希望這可以更好地瞭解我正在綁定的內容
你在你的程序中試圖做什麼是非生產性的。看起來你想要某種交叉表,但效率很低。你能否提供一些數據樣本......說3或4個「Depot_NR」條目值得原始數據。然後,顯示你期望的結果。這會給你更好的機會幫助你。 – DRapp