41分,41分求救:有关记录的问题,毫无头绪~~ ~~ 还望高手指教~~(41分)

  • 主题发起人 主题发起人 machin
  • 开始时间 开始时间
M

machin

Unregistered / Unconfirmed
GUEST, unregistred user!
[purple]
有个表 Table1 ,记录如下:

1 2001-09-01 12:30:40
1 2001-09-01 12:40:40
1 2001-09-01 12:50:40
1 2001-09-01 12:55:40
2 2001-09-02 11:20:40
2 2001-09-02 11:30:40
2 2001-09-02 13:30:40

请问:如何将以上记录形式保存在另一张表里 Table2 ,记录形式变为以下:

1 2001-09-01 12:30:40 2001-09-01 12:40:40 2001-09-01 12:50:40 2001-09-01 12:55:40
2 2001-09-02 11:20:40 2001-09-02 11:30:40 2001-09-02 13:30:40

[/purple]
 
Table1:
A B
1 2001-09-01 12:30:40
1 2001-09-01 12:40:40
1 2001-09-01 12:50:40
1 2001-09-01 12:55:40
2 2001-09-02 11:20:40
2 2001-09-02 11:30:40
2 2001-09-02 13:30:40

Table2:
Field0 Field1 Field2 Field3 Field4 Field5......
1 2001-09-01 12:30:40 2001-09-01 12:40:40 2001-09-01 12:50:40 2001-09-01 12:55:40
2 2001-09-02 11:20:40 2001-09-02 11:30:40 2001-09-02 13:30:40

Code:
Var
FieldNo,CurtA: Integer;
begin
fieldNo:=0;
CurtA:=0;
query2.close;
query2.sql.text:='select * from table2';
query2.open;
query1.close;
query1.sql.text:='select A,B from table1 order by A';
query1.open;
Query1.first;
while not query1.eof do
begin
if query1.fieldbyname('A').AsInteger>A then
begin
CurtA;=query1.fieldbyname('A').AsInteger;
query2.append;
query2.fieldbyname('field0').asinteger:=curtA;
query2.fieldbyname('field1').asDatetime:=query1.fieldbyname('B').asdatetime;
query2.post;
fieldNO:=2;
continue;
end;
if query1.fieldbyname('A').AsInteger=A then
begin
query2.edit;
query2.fieldbyname('field'+inttostr(fieldNO)).asDatetime:=query1.fieldbyname('B').asdatetime;
query2.post;
inc(fieldNO);
continue;
end;
query1.next;
end;
end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
631
import
I
后退
顶部