 |
shahidmojid Level: Professor
 Registered: 09-05-2002 Posts: 85
|
How to make two databases link
I having difficulty to make link with two databases.
First database - abc.mdb fields x1,x2, x3 - primary key x1
Second database - xyz.mdb field x1, y2, y3 - x1 -> index (no duplicate)
I want to display x1, x2, x3, y2, y3 join field x1. Can someone help me with the full SQL command.
Thanks in advance.
|
|
13-09-2002 at 01:04 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: How to make two databases link
SELECT [abc].x1, [abc].x2, [abc].x3, [xyz].x1, [xyz].y2, [xyz]y3
FROM [abc] INNER JOIN [xyz] ON [abc].x1 = [xyz].x1
Of course, if you use the query builder in Access or SQL, you can do it graphically, which is a lot easier.
|
|
13-09-2002 at 06:16 PM |
|
|
shahidmojid Level: Professor
 Registered: 09-05-2002 Posts: 85
|
Re: How to make two databases link
Thanks JL. I have bigger problem than this.
I have three databases in three different locations.
1. Report.mdb -> tablename (report) -> fieldsName (extension, dialed, COS)
2. 020827-o.mdb -> tablename (outgoing) -> fieldsName (extension, dialed, type)
3. site.mdb -> tablename (extensions) -> fieldsName (extension, COS)
What I want to do is, insert all data from 020827-0.mdb->outgoing-> fields (dialed, extension) to report.mdb-> report->fields (dialed, extension) where outgoing!type = 'L' and
Update report.mdb->report->COS where site.mdb->extensions![extension] = report.mdb->report![extension] (needs to make inner join)
I tried with the below commands for the first part but doesn’t work
open dbs 020827-0.mdb
lsSQL = "INSERT INTO report IN '" & App.Path & "reportsreport.mdb' ([extension], [dialed]) select [outgoing].[extension], [outgoing].[dialed] from [OUTGOING] where outgoing![type] = 'L'"
DBs.Execute lsSQL
got "syntax error in INSERT INTO COMMAND".
I am using vb5 and access97. In the help menu shows insert into command as follows: INSERT INTO target [IN externaldatabase] [(field1[, field2[, ...]])] SELECT [source.]field1[, field2[, ...] From tableexpression
Can someone please check where I have made a mistake? and please send me a fresh idea along with code for the queries.
Its very important for me and i will be really appreciated for any help.
Thanks in advance.
|
|
14-09-2002 at 09:35 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: How to make two databases link
Long day, so can't think too hard.
There's info in the MSDN library: "INSERT INTO", under the "external databases" section
IT shows uses the "IN" command in the select part, not the insert. (IE, have the INSERT INTO table be in the current database, SELECT table be the remote db).
However it does suggest using a Linked table over a SQL command with external databases.
[Edited by JLRodgers on 14-09-2002 at 03:47 PM GMT]
|
|
14-09-2002 at 09:44 PM |
|
|
shahidmojid Level: Professor
 Registered: 09-05-2002 Posts: 85
|
Re: How to make two databases link
thanks for your prompt reply. i will try again as you said.
Also, if you can take sometime to look at it and send me codes later.
Thanks a lot.
|
|
14-09-2002 at 09:53 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: How to make two databases link
Just noticed, your code had:
reportsreport.mdb
your database names had it as: report.mdb.
If the two names are correct, that could be a problem.
I created the databases (report, and 020827-o) and 1 table each (report with 2 columns, 020827-o with 3).
In the 020827-o database (I just stuck the query there) the following query did work (it's how accessXP formatted it and everything ):
INSERT INTO Report ( extension, dialed ) IN "Report.mdb"
SELECT extension AS extension, dialed AS dialed
FROM Outgoing
WHERE Type='L';
[Edited by JLRodgers on 14-09-2002 at 04:12 PM GMT]
|
|
14-09-2002 at 09:57 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: How to make two databases link
Never tried to update fields with multiple database tables, but the gerenal update syntax is:
UPDATE tablename SET fieldname=value WHERE conditions
|
|
15-09-2002 at 11:27 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: How to make two databases link
If the tables in the SQL statement are in the same database, just modifying the query should work. (note that the destination table must have the same field names).
INSERT INTO [tablenamedest]
SELECT Classes.Cos, Classes.Name, Extensions.Extension, Extensions.FirstName FROM Classes INNER JOIN Extensions ON Classes.Cos = Extensions.Cos
By using a recordset, there isn't that I know of, but then I've never tried. I just use the query that created the recordset as above.
|
|
17-09-2002 at 01:18 AM |
|
|
|
|
 |
 |