on 2013 Mar 26 8:00 AM
That's a follow-up to this older and this current FAQ:
I'm basically trying to run queries over a few proxy tables declared in a 12.0.1.3817 database and located in a MS SQL 2008 R2 server. These queries are not very complex, i.e. mainly using joins over 3-5 proxy tables.
However, as soon as they do use an INNER JOIN and a LEFT JOIN, this doesn't work at all.
I seem to have either the choice (by setting the capability 'Unrestricted ANSI ON' OFF or ON):
However, the second approach at leads to the following incorrect syntax (the comma in the table list is rejected):
SELECT ... FROM (pt1, pt2) LEFT OUTER JOIN pt3 ON pt1.pk = pt3.pk WHERE pt1.pk = pt2.pk AND ...
Note, the original query does use an INNER JOIN between pt1 and pt2 here - which would work on MS SQL, too:
SELECT ... FROM pt1 INNER JOIN pt2 ON pt1.pk = pt2.pk LEFT OUTER JOIN pt3 ON pt1.pk = pt3.pk WHERE ...
So how can I force the remote query not to replace the INNER JOIN with a table list and a WHERE CLAUSE?
Note: If the query does only include INNER JOINs or LEFT JOINs, then they can be executed successfully, and then the inner join syntax is sent as such to the remote server...
Current setting of (possibly) relevant JOIN capabilities:
select * from syscapabilities where srvid = 1 and capid between 25 and 39
capid,srvid,capname,capvalue
25,1,Joins,T
26,1,Outer joins,T
27,1,Full outer joins,T -- set to ON (default is OFF), no obvious effect 28,1,Multiple outer joins,T
29,1,Logical operators in outer join,T
30,1,Outer joins mixed with normal joins,T
31,1,ANSI join syntax,T
32,1,TSQL join syntax,F
33,1,ODBC outer join syntax,T -- set to ON (default is OFF), no obvious effect
34,1,Unrestricted ANSI ON,T -- set to ON (default is OFF), if OFF, then the query is executed locally...
Request clarification before answering.
Looks like there is no way around this one. You will probably have to force no passthru for now or use sp_forward_to_remote_server() if you can. I will open a bug report and see if we can do a better job of building remote queries containing inner joins.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Karim, thanks for the clarification. Using sp_forward_to_remote_server() is not a solution here as the names and structures of remote and local tables do not match, and my goal is to run the existing application without having to adapt the database layer - see my comment in Thomas's suggestion.
Just another idea as a work around: I may be able to modify those queries to consist of left joins only - and then to add conditions in the where clauses for the "fake" null-supplying sides to turn them into actual inner joins, something like
SELECT ... FROM pt1 LEFT JOIN pt2 ON pt1.pk = pt2.pk LEFT OUTER JOIN pt3 ON pt1.pk = pt3.pk WHERE pt2.pk is not null AND ...
I may try this approach, simply as running in no passthrough mode is rather bad for performance reasons...
User | Count |
---|---|
82 | |
29 | |
9 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.