SQL 使用 OPENQUERY 加入
SQL JOIN with OPENQUERY
如何正确地将查询与打开的查询连接起来?
这是我的查询现在的布局方式。作为 OPENQUERY
一部分的查询可自行运行。
Select d.* from db.dbo.table d
left join (select * from OPENQUERY(otherSource,'
--working query
SELECT...
left join...
inner join..') OQ
ON d.col1 = OQ.col1
我正在捕获错误 'Incorrect syntax near 'ON'.
您可能需要撤消它,从 OPENQUERY 执行 SELECT。所以像:
SELECT * FROM OPENQUERY(remotesource,'SELECT blahblah from tableA) A
RIGHT JOIN tableB B ON B.col1 = A.col1
这个语法对我有用:
select
a.id, b.ItemId, a.Name, b.[Description]
from
[A_Database]..tblA a
inner join
openquery([linkedServerDbName], 'select * from [B_Database]..[TableToJoin]') b
ON
a.id = b.ItemId
如何正确地将查询与打开的查询连接起来?
这是我的查询现在的布局方式。作为 OPENQUERY
一部分的查询可自行运行。
Select d.* from db.dbo.table d
left join (select * from OPENQUERY(otherSource,'
--working query
SELECT...
left join...
inner join..') OQ
ON d.col1 = OQ.col1
我正在捕获错误 'Incorrect syntax near 'ON'.
您可能需要撤消它,从 OPENQUERY 执行 SELECT。所以像:
SELECT * FROM OPENQUERY(remotesource,'SELECT blahblah from tableA) A
RIGHT JOIN tableB B ON B.col1 = A.col1
这个语法对我有用:
select
a.id, b.ItemId, a.Name, b.[Description]
from
[A_Database]..tblA a
inner join
openquery([linkedServerDbName], 'select * from [B_Database]..[TableToJoin]') b
ON
a.id = b.ItemId