{*********************************************************************************}
var fSQL:textfile;
i:integer;
strFields:string;
strTableName:string;
begin
assignfile(fSQL,'C:\saveSQL.SQL');
rewrite(fSQL);
strTableName:='WpKC';
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('SELECT * FROM '+strTableName);
Query1.open;
if Query1.RecordCount >0 then
begin
strFields:='';
for i:=1 to Query1.FieldCount-1 do { 写入字段名,可省略 }
strFields:=strFields+Query1.Fields.FieldByNumber(i).FieldName+',';
strFields:=strFields+Query1.Fields.FieldByNumber(Query1.FieldCount).FieldName;
Query1.First;
repeat
write(fSQL,'insert into '+strTableName+'('+strFields+ ') Values(');
for i:=1 to Query1.FieldCount-1 do
write(fSQL,''''+Query1.Fields.FieldByNumber(i).AsString+''',');
write(fSQL,''''+Query1.Fields.FieldByNumber(Query1.FieldCount).AsString+''')');
Writeln(fSQL);
Query1.Next;
until Query1.Eof ;
Closefile(FSql);
end;
end;