• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Insert a Table into another Table

I Use ADOQuery, Provider=Microsoft.Jet.OLEDB.4.0

I want to insert a Table in another Table
I Tried:
   Query1.Close;
   Query1.SQL.Clear;
   Query1.sql.add('INSERT INTO Table1');
   Query1.sql.add('SELECT * from Table2');
   Query1.ExecSQL;
   Query1.SQL.Clear;
   Query1.sql.add('select * from Table1');
   Query1.Open;

But the compiler says Table2 is unknow, I'm sure Table2 exist and it had the same Fields as Table1
0
misterstefano
Asked:
misterstefano
  • 3
  • 2
1 Solution
 
kretzschmarCommented:
>the compiler says Table2 is unknow
the compiler?
usual if table 2 is missed you got an error only at runtime,
not at compiletime

maybe your problem is on another place?

meikl ;-)

btw. what database?
0
 
misterstefanoAuthor Commented:
I Use 2 access-databases

>the compiler says Table2 is unknow ---> When I want to RUN (F9) the program

I think the problem is here:
Query1 is linked (Provider=Microsoft.Jet.OLEDB.4.0) on Table1, I think thats the reason why Table2 is unknow
0
 
kretzschmarCommented:
hi,

you cannot use delphi-object names
in sql-statements, use the physical tablenames instead

just guessing

meikl ;-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
nafeelmCommented:
try this ;

  Query1.Close;
  Query1.SQL.Clear;
  Query1.sql.add('INSERT INTO database1..Table1');
  Query1.sql.add('SELECT * from database2..Table2');
  Query1.ExecSQL;

  Query1.SQL.Clear;
  Query1.sql.add('select * from database1..Table1');
  Query1.Open;
0
 
misterstefanoAuthor Commented:
nope, doesn't work.
The problem is that Query1 has connection with Table1 and not with Table2
0
 
misterstefanoAuthor Commented:
I found it, The code works:

 Query1.Close;
 Query1.SQL.Clear;
 Query1.sql.add('INSERT INTO database1.mdb..Table1');
 Query1.sql.add('SELECT * from database2.mdb..Table2');
 Query1.ExecSQL;

 Query1.SQL.Clear;
 Query1.sql.add('select * from database1.mdb..Table1');
 Query1.Open;
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now