- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
procedure TForm1.Button2Click(Sender: TObject);
var stSQL: string;
i: integer;
begin
try
SQLConnection1.Params.Values['HostName']:=Server; // имя сервера
SQLConnection1.Params.Values['DataBase']:=MyBase ;
SQLConnection1.Params.Values['OS Authentication']:= 'True';
SQLConnection1.Open;
except
MessageDlg('Соединение с БД невозможно', mtError, [mbOK], 0);
exit;
end;
SQLQuery1.SQL.Add('IF EXISTS (SELECT * FROM sysobjects WHERE name ='+''''+'MyTable'+''''+') DELETE FROM MyTable;');
SQLQuery1.ExecSQL;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('IF EXISTS (SELECT * FROM sysobjects WHERE name ='+''''+'MyTable'+''''+') DROP TABLE MyTable;');
SQLQuery1.ExecSQL;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('CREATE TABLE MyTable (VZPROJ varchar(50), PARTITION varchar(50), '+
'MAKER varchar(50), STATE varchar(50), DATECRT varchar(50), DATEP varchar(50), '+
'DATEF varchar(50), DATETOCRD varchar(50), DATECRD varchar(50), DATEPLN varchar(50), '+
'DATEFIN varchar(50), DATECNCL varchar(50))');
SQLQuery1.ExecSQL;
cdsList.First;
for i:=1 to cdsList.RecordCount do
begin
stSQL:='INSERT INTO MyTable VALUES(';
if cdsList.FieldByName('VZPROJ').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('VZPROJ').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('PARTITION').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('PARTITION').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('MAKER').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('MAKER').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('STATE').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('STATE').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATECRT').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('DATECRT').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATEP').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('DATEP').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATEF').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('DATEF').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATETOCRD').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('DATETOCRD').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATECRD').AsString<>'' then
stSQL:=stSQL+' "'+cdsList.FieldByName('DATECRD').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATEPLN').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('DATEPLN').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATEFIN').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('DATEFIN').AsString+''','
else
stSQL:=stSQL+' NULL,';
if cdsList.FieldByName('DATECNCL').AsString<>'' then
stSQL:=stSQL+' '''+cdsList.FieldByName('DATECNCL').AsString+''''
else
stSQL:=stSQL+' NULL';
stSQL:=stSQL+');';
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add(stSQL);
SQLQuery1.ExecSQL;
cdsList.Next;
end;
end;