关于(vfp)编程问题,再次请教tiger先生和和高手们
本人此前在本论坛请教,得到tiger先生和高手们的指导,现再次请教,为方便老师们指教,现把产生表格的程序列出:close all
clear
set safe off
use d1999 in 1
zap
use d2000 in 2
zap
use d2001 in 3
zap
close all
CREATE table d1999(hm c(4),ms01 n(4),ms02 n(4),ms03 n(4),ms04 n(4),ms05 n(4),ms06 n(4),ms07 n(4),ms08 n(4),ms09 n(4),ms10 n(4),ms11 n(4),ms12 n(4))
INSERT INTO d1999 VALUES ("雪碧",300,500,700,200,600,800,900,300,950,900,980,500)
INSERT INTO d1999 VALUES ("可乐",100,300,600,400,700,900,1200,1300,1450,1100,880,600)
brow
CREATE table d2000 (hm c(4),ms01 n(4),ms02 n(4),ms03 n(4),ms04 n(4),ms05 n(4),ms06 n(4),ms07 n(4),ms08 n(4),ms09 n(4),ms10 n(4),ms11 n(4),ms12 n(4))
Insert Into d2000 Values ("雪碧",100,200,300,400,500,600,800,900,1000,900,950,600)
Insert Into d2000 Values ("可乐",200,250,380,390,450,900,1050,1100,1550,800,680,500)
brow
CREATE table d2001 (hm c(4),ms01 n(4),ms02 n(4),ms03 n(4),ms04 n(4),ms05 n(4),ms06 n(4),ms07 n(4),ms08 n(4),ms09 n(4),ms10 n(4),ms11 n(4),ms12 n(4))
Insert Into d2001 Values ("雪碧",200,400,600,800,700,600,700,500,1050,600,850,700)
Insert Into d2001 Values ("可乐",360,280,580,690,650,670,850,800,1450,900,580,450)
brow
CREATE table tjb (hm c(4),ldDate1 d(8), ldDate2 d(8))
INSERT INTO tjb VALUES ( "雪碧", {^1999-3-1}, {^2001-10-31})
INSERT INTO tjb VALUES ( "可乐", {^1999-5-1},{^2001-5-31})
brow
close all
clear
set safe on
俺的问题是,如何用以下的程序,对tjb表所要求的两个品种和期限进行统计?并同时得出这两个品种的结果表。
ldDate1=date(1999,9,1)
ldDate2=date(2002,12,30)
lcHm='雪碧'
lcSQL='create table tmp1 (ss n(4),hm c(10)'
for i=year(ldDate1) to Year(ldDate2)
for j=iif(i=year(ldDate1),month(ldDate1),1) to iif(i=year(ldDate2),month(ldDate2),12)
lcSQL=lcSQL+',ms'+str(i,4)+padl(j,2,'0')+' n(6)'
endfor
endfor
lcSQL=lcSQL+',mstotal n(6))' &&lcSQL=lcSQL+'mstotal n(6))'
&lcSQL
select tmp1
locate all for alltrim(hm)==lcHm
if eof()
append blank
replace hm with lcHm
endif
nTot=0
for i=year(ldDate1) to year(ldDate2)
cTable='d'+str(i,4)
use (cTable) in 2 alias tmp2
select tmp2
locate for alltrim(hm)==lcHm
if eof()
loop
endif
for j=iif(i=year(ldDate1),month(ldDate1),1) to iif(i=year(ldDate2),month(ldDate2),12)
select tmp2
lnFieldValue=evaluate(field(j+2))
select tmp1
lcFieldName='ms'+str(i,4)+padl(j,2,'0')
replace (lcFieldName) with lnFieldValue
nTot=nTot+lnFieldValue
endfor
endfor
select tmp1
replace mstotal with nTot
brow