【问题标题】:SQL JOIN with OPENQUERYSQL JOIN 与 OPENQUERY
【发布时间】:2016-07-27 14:34:43
【问题描述】:

如何正确地将查询与打开的查询连接起来? 这是我的查询现在的布局方式。属于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'.

【问题讨论】:

    标签: sql sql-server join left-join openquery


    【解决方案1】:

    这个语法对我有用:

    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
    

    【讨论】:

      【解决方案2】:

      您可能需要反转它,从 OPENQUERY 中进行选择。所以像:
      SELECT * FROM OPENQUERY(remotesource,'SELECT blahblah from tableA) A
      RIGHT JOIN tableB B ON B.col1 = A.col1

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-29
        相关资源
        最近更新 更多