Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ewomack
Starting Member
33 Posts |
Posted - 2011-02-07 : 14:06:52
|
Hello,If this is possible it will simplify my life incredibly.Can I join to a linked server using OpenQuery?Right now my join code is:INNER JOIN OpenQuery(LinkedServer, @sql) AS rq ON sr.ID = rq.ID The @sql contains a dynamic query that access a function on the linked server. I should also mention that I'm on a SQL 2000 box (through no fault of my own ).Thank you!Ed Womackwww.getmilked.com |
|
|
ewomack
Starting Member
33 Posts |
Posted - 2011-02-07 : 14:13:39
|
| Sorry, I should have also mentioned that the current code is giving me an "incorrect syntax" error on the join line I posted and I've been trying to escape out the quotes to no avail (yet).Ed Womackwww.getmilked.com |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-02-07 : 14:22:41
|
| You can't execute it that way. The ENTIRE statement, including the OPENQUERY portion and the JOIN, would have to be in the @sql variable.Also, you do NOT want to join local tables to remote data sources, either with OPENQUERY or 4 part names. It is better to pull all of the data from OPENQUERY into a local (temp) table and join the remaining local tables to it instead. |
 |
|
|
ewomack
Starting Member
33 Posts |
Posted - 2011-02-07 : 14:41:59
|
| Thank you, this method was suggested to me by someone else and I was skeptical when I couldn't get it to work. I will go back to temp tables, which was where I started.Thanks!Ed Womackwww.getmilked.com |
 |
|
|
|
|
|