Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Joining tables from 2 different databases
Message
From
23/07/1998 11:46:34
 
 
To
23/07/1998 11:40:17
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00120449
Message ID:
00120507
Views:
15
>>>I have been through the files here, on the microsoft site and even bought a SQL book to get me going, but no one seems to directly address my situation:
>>>On this job I have multiple servers that contain SQL databases. One project I'm working on now requires me to get a join from 2 tables from 2 different databases. One database table contains the info I need and a SS#. The other database contains the name and address info to go with the SS#. It seems that the best idea would be to keep those tables together, but that is not an option for me.
>>>When I send this command:
>>>SQLPREPARE(myhandle,"SELECT * from courses","TEMPCOURSES")
>>>the handle puts me directly into one database, so I'm not sure how I can address a table in another database for the join.
>>>I tried using the query builder wizard, remote view wizard and MS Query to see how they would handle the situation and they don't seem to go far enough to do this kind of work. The help file for MS SQL Server 6.5 intimates that it is possible, but doesn't say how to do it. I'm running this from a web page, Foxweb, VFP 5.0 and MS SQL server.
>>>TIA
>>
>>You should provide full reference to table which is not in current database:
>>Select * From Databasename.dbo.Tablename
>
>Thanks for the quick help. I like the idea of only being away from functionality by a period or so, but I'm still not able to run this...here's how the code stands:
>
>STORE SQLCONNECT('EducationSQLData','OURID','OURPASSWORD') TO gnConnHandle
>=SQLPREPARE(gnConnHandleA,"SELECT * FROM studcour,Dreams.dbo.students WHERE (Dreams.dbo.students.ssn=scssn)","TEMPCOUR")
>=sqlexec(gnConnHandleA)
>
>
>Dreams=the Database Name
>Students= the table in Dreams
>DreamsSQLData= the Database Name Source in the ODBC driver.
>EducationSQLData= the Database Name Source that contains the Studcour table
>Scssn=the social security number field in Studcour
>ssn= the social security number field in Students
>
>I tried refering to the students table by Name Source and Database Name but the return answer is that my prepare statement didn't fly...I also don't get how it could open up the DreamsSQLData source without the ID and password. Many thanks for your help so far.

I guess you better call stored procedure with this SQL-statement. At least, it will be easier for you to debug. Also, you will get ability:
1. Include GRANT commands to get necessary permissions to another database.
2. Run this SQL-statement faster.
Edward Pikman
Independent Consultant
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform