close all
create table tblTemp (日期 N(4),客户 C(8),金额 N(4),顺序号 N(1))
insert into tblTemp values (2009,'XM', 50,1)
insert into tblTemp values (2009,'XM', 60,1)
insert into tblTemp values (2009,'XM', 70,1)
insert into tblTemp values (2009,'XM', 80,1)
insert into tblTemp values (2009,'JM',100,2)
insert into tblTemp values (2009,'JM',100,2)
insert into tblTemp values (2009,'JM',200,2)
insert into tblTemp values (2009,'JM',300,2)
insert into tblTemp values (2009,'JM',400,2)
select count(*) as cnt from tbltemp group by 客户 into table tblTemp1
select max(cnt) from tblTemp1 into array laMyArr
lc='(日期 N(4),客户 C(8),金额 N(4)'
for lnCnt=1 to laMyArr(1)-1
lc=lc+',金额'+alltrim(str(lnCnt))+' N(4)'
endfor
lc=lc+',顺序号 N(1))'
create table tblTemp2 &lc
select tblTemp
scan
select tblTemp2
locate for 客户=tblTemp.客户
if eof()
append blank
replace 日期 with tblTemp.日期,客户 with tblTemp.客户,金额 with tblTemp.金额,顺序号 with tblTemp.顺序号
else
for lnCnt=4 to fcount()-1
lc=field(lnCnt)
if empty(&lc)
exit
endif
endfor
replace &lc with tblTemp.金额
endif
endscan
select tblTemp2
brow
return