Convert a Query into a Table
1 2 3 4 5 6 7 8 9 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 |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables; type TForm1 = class(TForm) Button1: TButton; Query1: TQuery; DataSource1: TDataSource; DBGrid1: TDBGrid; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var InitQuery: TQuery; InitTable: TTable; InitBatch: TBatchMove; begin InitQuery := TQuery.Create(Application); with InitQuery do begin DatabaseName := 'DBDEMOS'; Close; SQL.Clear; SQL.Add('SELECT * '); SQL.Add('FROM customer.db'); SQL.Add('WHERE Country="US"'); SQL.SaveToFile('mgrInit.sql'); try Open; try // Send the SQL result to c:tempINIT.DB InitTable := TTable.Create(Application); with InitTable do begin DatabaseName := 'c:temp'; TableName := 'INIT'; end; InitBatch := TBatchMove.Create(Application); with InitBatch do begin Destination := InitTable; Source := InitQuery; Mode := batCopy; Execute; end; finally InitTable.Free; InitBatch.Free; end; except Free; Abort; end; Free; end; end; end. |