当前位置: 代码迷 >> VFP >> 请问,怎么编程实现代码语句也随月份变动实现动态变化
  详细解决方案

请问,怎么编程实现代码语句也随月份变动实现动态变化

热度:9727   发布时间:2013-02-26 00:00:00.0
请教,如何编程实现代码语句也随月份变动实现动态变化?
请教各位老师,当日期的月份推移时,想使以下语句名称也移动一个月的表示,例如:
1)当:Edate=2011-12-28(指2011年12月内的某一天)
Repl ntotal with (Y1012+Y1101+Y1102+Y1103+Y1104+Y1105+Y1106+Y1107+Y1108+Y1109+Y1110+Y1111)

2)当:Edate=2012-01-01(指2012年1月内的某一天)
Repl ntotal with (Y1101+Y1102+Y1103+Y1104+Y1105+Y1106+Y1107+Y1108+Y1109+Y1110+Y1111+Y1112)

2)当:Edate=2012-02-01(指2012年2月内的某一天)
Repl ntotal with (Y1102+Y1103+Y1104+Y1105+Y1106+Y1107+Y1108+Y1109+Y1110+Y1111+Y1112+Y1201)
…………………………
…………………………
请各位老师指教,非常感谢

------解决方案--------------------------------------------------------
SQL code
Create Table tt1 (cname c (8),edate d,Y1012 N(9,2),Y1101 N(9,2),Y1102 N(9,2),Y1103 N(9,2),;    Y1104 N(9,2),Y1105 N(9,2),Y1106 N(9,2),Y1107 N(9,2),Y1108 N(9,2),Y1109 N(9,2),Y1110 N(9,2),;    Y1111 N(9,2),Y1112 N(9,2),Y1201 N(9,2),Y1202 N(9,2),ntotal N(12,2),ptotal N(12,2))Insert Into tt1(cname,edate,Y1012,Y1101,Y1102,Y1103,Y1104,Y1105,Y1106,Y1107,Y1108,Y1109,Y1110,;    Y1111,Y1112,Y1201,Y1202,ntotal,ptotal);    Values ("hans",{^2011-12-28},250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,0,0)Insert Into tt1(cname,edate,Y1012,Y1101,Y1102,Y1103,Y1104,Y1105,Y1106,Y1107,Y1108,Y1109,Y1110,;    Y1111,Y1112,Y1201,Y1202,ntotal,ptotal);    Values ("mimi",{^2012-2-28},250,251,252,253,254,255,256,257,258,259,260,261,262,265,266,0,0)Insert Into tt1(cname,edate,Y1012,Y1101,Y1102,Y1103,Y1104,Y1105,Y1106,Y1107,Y1108,Y1109,Y1110,;    Y1111,Y1112,Y1201,Y1202,ntotal,ptotal);    Values ("cici",{^2012-2-22},0,0,0,0,254,255,256,257,258,259,260,261,262,265,266,0,0)Insert Into tt1(cname,edate,Y1012,Y1101,Y1102,Y1103,Y1104,Y1105,Y1106,Y1107,Y1108,Y1109,Y1110,;    Y1111,Y1112,Y1201,Y1202,ntotal,ptotal);    Values ("tony",{^2012-2-1},0,0,0,0,0,0,256,257,258,259,260,261,262,265,266,0,0)BrowseReplace All ntotal With Evaluate(Substr(myfunc1(Edate),3)),ptotal With Iif(Val(Left(myfunc1(Edate),2))=0,0,ntotal/Val(Left(myfunc1(Edate),2)))BrowseFunction myfunc1    Lparameters tdEdate    Local Sdate,lcStr,lnI,lcField,lnMonths    lnMonths=0    Sdate=Gomonth(tdEdate-Day(tdEdate)+1,-12)    lcStr=''    For lnI=0 To 11        lcField='+Y'+Substr(Dtos(Gomonth(Sdate,lnI)),3,4)        lcStr=lcStr+lcField        If Evaluate(lcField)>0            lnMonths=lnMonths+1        Endif    Endfor    Return Padl(lnMonths,2,'0')+Substr(lcStr,2)Endfunc
------解决方案--------------------------------------------------------
edate=你的日期
mtotal=0
n=0
for i=-12 to -1
nn=mtotal
ss='mtotal=mtotal+y'+subs(dtos(gomonth(edate,i)),3,4)
&ss
n=iif(nn=mtotal,n,n+1)
endf
Repl ntotal with mtotal
if n>0
平均数=mtotal/n
endi

  相关解决方案