R
rmh
Unregistered / Unconfirmed
GUEST, unregistred user!
例如:表有'rq','payment'两个字段,设定当前日期为'2001-06-30',则
如何自动向表中'rq'字段输入如下数据
'2001-06-30'
'2001-07-30'
'2001-08-30'
'2001-09-30'
...
...
'2002-05-30'
有朋友给出如下程序:
var yy,mm,dd : word;
i,j,k: Integer;
begin
decodedate(date,yy,mm,dd);
yy:=yy-1;
mm:=mm;
k:=dd;
with query1 do
begin
Close;
SQL.Clear;
SQL.Add('Insert into table (rq) valuesrq1)');
end;
for i:=0 to 11 do
begin
j:=(mm+i) mod 12;
if j=0 then j:=12;
if (j=2) and (dd>28) then k:=28;
Query1.ParamByName('rq1').asDateTime
:=EnCodeDate(yy,mm,dd);
Query1.ExecSQL;
if j=12 then yy:=yy+1;
k:=dd;
end;
end;
运行结果如下:
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
月份没有根据要求变化.
如何自动向表中'rq'字段输入如下数据
'2001-06-30'
'2001-07-30'
'2001-08-30'
'2001-09-30'
...
...
'2002-05-30'
有朋友给出如下程序:
var yy,mm,dd : word;
i,j,k: Integer;
begin
decodedate(date,yy,mm,dd);
yy:=yy-1;
mm:=mm;
k:=dd;
with query1 do
begin
Close;
SQL.Clear;
SQL.Add('Insert into table (rq) valuesrq1)');
end;
for i:=0 to 11 do
begin
j:=(mm+i) mod 12;
if j=0 then j:=12;
if (j=2) and (dd>28) then k:=28;
Query1.ParamByName('rq1').asDateTime
:=EnCodeDate(yy,mm,dd);
Query1.ExecSQL;
if j=12 then yy:=yy+1;
k:=dd;
end;
end;
运行结果如下:
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2001-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
'2002-06-30'
月份没有根据要求变化.