// table name, the key field name, a single SQL statement, resulting in a new record value of function Tfrmdmmain.CopyTbale ( const TableName, fileldname, swhere, newfileldstring: String ): Integer; var SQL, SqlString, sqlvalue, newsqlvalue: String ; I: Integer; the begin SQL: = ' the INSERT the INTO [% S] (% S) the VALUES (% S) ' ; self.fykExecute.Close; self.fykExecute.SQL.Text: = swhere; self.fykExecute.Open; // get the field data, pay attention here on the field type of judgment, and handling of NULL. For SQLSERVER SqlString: = StringReplace (Trim (fykExecute.FieldList.Text), # 13 # 10, ',', [rfReplaceAll]); for i := 0 to fykExecute.FieldCount -1 do begin if fykExecute.Fields[i].FieldName = fileldname then begin sqlvalue :=sqlvalue + newfileldstring +','; end else begin if fykExecute.Fields[i].DataType in [ftString , ftDate, ftTime, ftDateTime, ftMemo, ftFmtMemo, ftWideString] then begin if fykExecute.Fields[i].AsString <>'' then begin sqlvalue :=sqlvalue +''''+ fykExecute.Fields[i].AsString +''','; end else begin sqlvalue :=sqlvalue +'NULL'+','; end; end else begin if fykExecute.Fields[i].AsString <>'' then begin sqlvalue :=sqlvalue + fykExecute.Fields[i].AsString +','; elsethan begin sqlvalue :=sqlvalue +'NULL'+','; end; end; end; end; newsqlvalue:= copy(sqlvalue,0,length(sqlvalue)-1) ; // showessage(sqlvalue); self.fykExecute.Close ; self.fykExecute.SQL.Text := format(sql,[tablename,sqlstring,newsqlvalue]); fykExecute.SQL.SaveToFile('C:\1.TXT'); Resuntl := self.fykExecute.ExecSQL ; end;