Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Union of smaller table
Wed, Sep 17 2008 10:57 AMPermanent Link

"C.M."
Hi
I have two table.
Table A: many fields (F1, F2, F3, F4, F5, F6,F7 .....  and so on) and is
empty
Table B: only 3 fields F1, F2 and F3 full of data !

I need to "append" the data of table B on table A using NULL for the non
existents fields.

The structure of table B is variable

Thanks, and sorry for my english !

C.M.

Wed, Sep 17 2008 12:31 PMPermanent Link

"Robert"

"C.M." <c.m.@senzaemail.com> wrote in message
news:D10BC071-726A-4E0A-958B-3F0977B582B2@news.elevatesoft.com...
> Hi
> I have two table.
> Table A: many fields (F1, F2, F3, F4, F5, F6,F7 .....  and so on) and is
> empty
> Table B: only 3 fields F1, F2 and F3 full of data !
>
> I need to "append" the data of table B on table A using NULL for the non
> existents fields.
>
> The structure of table B is variable
>

INSERT INTO A (F1, F2, F3) SELECT F1, F2, F3 FROM B

But that business about the structure of B being variable makes me think
that you need something else. You might have to build the SQL similar to the
one above, but using B's field names.

var s : string;
   j : integer;
begin
 s := '';
 B.Open;

 for j := 0 to B.FieldDefs.Count - 1 do begin
   if s = '' then s := B.FieldDefs[j].Name
     else s := s + ', ' + B.FieldDefs[j].Name;
 end;

and stick S into the two places above where you see F1, F2, F3

Robert


Thu, Sep 18 2008 6:17 AMPermanent Link

"C.M."

"Robert" <ngsemail2005withoutthis@yahoo.com.ar> ha scritto nel messaggio
news:BB953C96-90B8-4D3F-8BFF-2FB0E5A8F980@news.elevatesoft.com...
>
> "C.M." <c.m.@senzaemail.com> wrote in message
> news:D10BC071-726A-4E0A-958B-3F0977B582B2@news.elevatesoft.com...
>> Hi
>> I have two table.
>> Table A: many fields (F1, F2, F3, F4, F5, F6,F7 .....  and so on) and is
>> empty
>> Table B: only 3 fields F1, F2 and F3 full of data !
>>
>> I need to "append" the data of table B on table A using NULL for the non
>> existents fields.
>>
>> The structure of table B is variable
>>
>
> INSERT INTO A (F1, F2, F3) SELECT F1, F2, F3 FROM B
>
> But that business about the structure of B being variable makes me think
> that you need something else. You might have to build the SQL similar to
> the one above, but using B's field names.
>
> var s : string;
>    j : integer;
> begin
>  s := '';
>  B.Open;
>
>  for j := 0 to B.FieldDefs.Count - 1 do begin
>    if s = '' then s := B.FieldDefs[j].Name
>      else s := s + ', ' + B.FieldDefs[j].Name;
>  end;
>
> and stick S into the two places above where you see F1, F2, F3
>
> Robert
>
>
>

Thank you  Robert
very helpful example !

C.

Image