Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQLExec() SQL Select from 2 DB
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01654292
Message ID:
01654306
Views:
47
>>>>>>
select Table1.fielda from Table1 left join db2.dbo.Table2 on Table1.pk = Table2.pk where table2.field2 = '1234' 
>>>>-- assumming the schema is dbo and the database is db2 for table 2
>>>>>>
>>>>>>if is not in the same instance then you will need to create a linked server on the first instance and add the linked server in a four part naming [linked server].[database].[schema].[table]
>>>>>
>>>>>I think when you are saying "instance" you mean instance of SQL Server. In my case, it is the same instance of the SQL Server but different databases. As in your code, 'db2' is a different database on the same SQL Server.
>>>>>And I suppose that since SQLEXEC uses the handle for one database, the code won't work. Am I understanding correctly?
>>>>
>>>>It will work. The dbname.dbo.table.field allows you to use tables from other databases on the same instance. For that matter, you don't really need two handles if you use that syntax.
>>>
>>>What confuses me is that how does SQLEXEC() connects to the second database? Doesn't it need credentials to connect to the second database?
>>
>>If the user does not have rights for both databases then you might want to think about creating a view and then you just run a query on that view
>
>Or, as Borislav suggested, I may have to break the query. Thank you.

Breaking the query as in querying twice and then doing the join in FoxPro? I would be careful with that approach as you might have difficulties bringing the right records from the second table, unless is a small table that you can bring whole.
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform