Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Joining table for another SQL Server DB
Message
From
20/03/2019 16:04:39
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01667405
Message ID:
01667411
Views:
49
>Hi,
>
>I have a situation where in the SQL Select, the JOIN should have a table (MyTable2) from another SQL Server database. Here is an example:
>
>local cJoinSqlServer
>cJoinSqlServer = "SQL2Name.dbo."
>cSqlSelect = "select * from mytable join " + cJoinSqlServer + "MyTable2 on MyTable.pk_field = MyTable2.pk_field"
>
>The above syntax works.
>And then I tried to add the cJoinSqlServer to the ON part as follows:
>
>local cJoinSqlServer
>cJoinSqlServer = "SQL2Name.dbo."
>cSqlSelect = "select * from mytable join " + cJoinSqlServer + "MyTable2 on MyTable.pk_field = " + cJoinSqlServer + "MyTable2.pk_field"
>
>
>The above works too; no error. But do I really need to add this prefix (of the second SQL Server DB) to the ON part?

You'd likely need to if there was a potential ambiguity.

If the longer format looks too "cluttered" for your taste, perhaps using aliases could make it look tidier.
local cJoinSqlServer
cJoinSqlServer = "SQL2Name.dbo."
cSqlSelect = "select * from mytable as T1 join " + cJoinSqlServer + "MyTable2 as T2 on T1.pk_field = T2.pk_field"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform