Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Joining table for another SQL Server DB
Message
De
20/03/2019 16:04:39
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01667405
Message ID:
01667411
Vues:
50
>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"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform