🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.database.win32
4 messages
4 total messages Started by diktyo Fri, 17 Aug 2007 11:25
Query to Table
#249
Author: diktyo
Date: Fri, 17 Aug 2007 11:25
15 lines
1176 bytes
I see the need to "duplicate" a query to a - temporary - table.

That is, I must have a table with the exact field structure as the
query and all the data in it.

Is there a way to achieve this quickly or do I have to go field by
field definition, record by record.

I am lookinh for somethinh generic, so it must not be tied to specific
database.


Thanks

Petros
Re: Query to Table
#250
Author: Vassiliev V. V.
Date: Fri, 17 Aug 2007 13:26
32 lines
1953 bytes
An easy way that will work in most DBMS is select ... into query

select *
into <tmpTable>
from <MyTable>

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"diktyo" <diktyo@axd.forthnet.gr> ???????/???????? ? ???????? ?????????: 
news:46c585b7$1@newsgroups.borland.com...
>I see the need to "duplicate" a query to a - temporary - table.
>
> That is, I must have a table with the exact field structure as the
> query and all the data in it.
>
> Is there a way to achieve this quickly or do I have to go field by
> field definition, record by record.
>
> I am lookinh for somethinh generic, so it must not be tied to specific
> database.
>
>
> Thanks
>
> Petros 
Re: Query to Table
#101
Author: julio
Date: Mon, 20 Aug 2007 16:03
25 lines
1537 bytes
You could use something like this:

procedure CopyToTableFromQuery(queryOrigin, TableDestiny: TDataset);
begin

   queryOrigin.First;
   while not queryOrigin.Eof do begin
     TableDestiny.Append;
     for I := 0 to TableDestiny.FieldCount - 1 do begin
       if queryOrigin.FindField(TableDestiny.FieldList[I].FieldName) <> 
Nil then
         TableDestiny..FieldList[I].Value := 
query.FieldValues[TableDestiny.FieldList[I].FieldName];
     end;
   end;

end;

I like to work with memory tables, like TkbmMemTable wich is free, so 
you don't need to deal with physical creation/destruction of the 
temporary table.

Regards,

Julio Saucedo
Re: Query to Table
#102
Author: ssamayoa
Date: Mon, 20 Aug 2007 18:53
22 lines
1054 bytes
>select *
>into <tmpTable>
>from <MyTable>

Which RDBMS?

In Oracle and Firebird is:

insert into <table> [ (<field(s)>) ]
select ...

Or you can create the table in Oracle:

create table <table name>
as
select ...

Regards.



--- posted by geoForum on http://delphi.newswhat.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads