set talk off
set safety off
close all
ldDate1=date(1999,9,1)
ldDate2=date(2001,4,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+')'
&lcSQL
select tmp1
locate all for alltrim(hm)==lcHm
if eof()
append blank
replace hm with lcHm
endif
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
endfor
endfor
select tmp1
brow