Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with SQL involving 2 DBCs
Message
De
18/03/2004 12:59:08
 
 
À
18/03/2004 12:14:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00887579
Message ID:
00887599
Vues:
8
>Hello.
>
>I'm using VFP8 and SQL Server 2000
>
>I have DSNs for 2 DIFFERENT databases on the SQL Server.
>I open each via SQLSTRINGCONNECT:
>
>rsConnect1 = SQLSTRINGCONNECT('dsn=SQLDatabaseA;uid=myUserID;pwd=myPassword',lShared)
>rsConnect2 = SQLSTRINGCONNECT('dsn=SQLDatabaseB;uid=myUserID;pwd=myPassword',lShared)
>
>I create an SQL statement with a JOIN between a table in Database A, and a table in Database B.
>and assign the string to the variable mQuest1
>
>SELECT Abase.lname,Bbase.orderdate,Bbase.orderamount FROM tableA!Abase ;
>LEFT OUTER JOIN tableB!Bbase ;
>ON Abase.OrderNum = Bbase.OrderNum
>
>= SQLPREPARE(rsConnect2,mQuest1)
>= SQLEXEC(rsConnect1)
>
>I get a SQL Error message stating Line 1: Incorrect syntax near '!'
>
>If I remove the DBC reference (tableA!) I get the same error message.
>If I remove the DBC reference (tableB!) I get this: Invalid object name: 'Bbase'
>
>I tested the query code by creating the connections with Create Connection, created a Query that works fine,
>and cut and pasted the Query code into my prg. It still crashes, so it's not the statement
>but something about how I've opened or called the connections, I think......
>
>Can someone please point out my error?
>
>Thanks
>
>David

You are using VFP's SQL dialect on SQL Server. Both SQLs versions are not the same, they have many differences. For example you can't use "!" to do a "database!table" reference in SQL Server, you should use something like in: "database..table" to reference a table in another database (in between the two dots goes the owner of the database but in some circumstances it can be omitted, I don't remember those circumstances :) ). So your query could be like this (do not use semicolons between the lines):

SELECT TableA.lname,TableB.orderdate,TableB.orderamount
FROM BaseA..TableA TableA
LEFT OUTER JOIN BaseB..TableB TableB ON TableA.OrderNum = TableB.OrderNum


I hope this helps.

Luis
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform