SQL Server UPDATE OPENQUERY

时间:2014-02-21 14:30:10

标签: sql-server tsql linked-server openquery

我正在尝试链接两台服务器(主机是SQL Server 2008,目标是ORACLE),以便oracle服务器上的表由SQL服务器上多个表中保存的数据填充。

我已经设置了一个INSERT OPENQUERY,它可以很好地工作。我还想设置另一个查询来更新这些记录。

因此,我的插入查询,选择在过去24小时内创建的记录,并插入它们,没问题。但我正在努力创建一个UPDATE OPENQUERY脚本,它将每24小时运行一次以进行相关更改。

这是我的INSERT

INSERT OPENQUERY(ukdev662, 'SELECT DOCKET_NUMBER, 
                        APP_NUMBER,
                        ATT,
                        LIT_H, 
                        REVIEW,
                        COUNTRY,
                        NOTICE, 
                        COUNTRY_CODE,
                        FORMALITY_NAME                  
                        FROM GWDMDV29.LOOKUPS__IPMANAGER')
        SELECT PMasters.DocketNumber + ISNULL(Codes_RelationType.Code, '') + ISNULL(PMasters.FilingNumber, '') + 'PTE'
               ,ISNULL(PMasters.AppNumber, '[null]')
               ,ISNULL(PartyDetails_Att.Party, 'Att not assigned')
               ,0
               ,CONVERT(DATETIME, '20130128')
               ,uktst1633.dbo.Countries.Description
               ,'Preserve'
               ,uktst1633.dbo.Countries.WIPO
               ,ISNULL(PartyDetails_Associate.Party, '[null]')
            FROM uktst1633.dbo.Countries
            RIGHT OUTER JOIN uktst1633.dbo.PatentMasters PMasters
                ON ( PMasters.Country = uktst1633.dbo.Countries.CountryID )
            INNER JOIN uktst1633.dbo.Codes Codes_CType
                ON ( PMasters.CType = Codes_CType.CodeID
                     AND Codes_CType.CodeTypeID = 'CSP'
                   )
            INNER JOIN uktst1633.dbo.Codes Codes_RelationType
                ON ( Codes_RelationType.CodeID = PMasters.RelationType
                     AND Codes_RelationType.CodeTypeID = 'RLP'
                   )
            LEFT OUTER JOIN uktst1633.dbo.Parties Parties_Att
                ON ( Parties_Att.PartyID = PMasters.Att
                     AND ( Parties_Att.PartyTypeID = 'ATP'
                           OR Parties_Att.PartyTypeID IS NULL
                         )
                   )
            LEFT OUTER JOIN uktst1633.dbo.PartyDetails PartyDetails_Att
                ON ( PartyDetails_Att.PartyDetailID = Parties_Att.PartyDetailID )
            LEFT OUTER JOIN uktst1633.dbo.Parties Parties_Associate
                ON ( Parties_Associate.PartyID = PMasters.Associate
                     AND ( Parties_Associate.PartyTypeID = 'AGP'
                           OR Parties_Associate.PartyTypeID IS NULL
                         )
                   )
            LEFT OUTER JOIN uktst1633.dbo.PartyDetails PartyDetails_Associate
                ON ( PartyDetails_Associate.PartyDetailID = Parties_Associate.PartyDetailID )
            WHERE ( ( Codes_RelationType.Description = 'CONTINUATION'
                      OR Codes_RelationType.Description = 'DIVISION'
                    )
                    AND Codes_CType.Description = 'Regular'
                    AND PMasters.CreateDate >= DATEADD(day, -1, GETDATE())
                  )

感谢您的帮助。我在周围搜索过,在OPENQUERY上找不到多少,这似乎都是非常基本的东西。我试着遵循这个语法的例子,但它让我无处可以......

UPDATE
    Table
SET
    Table.col1 = other_table.col1,
    Table.col2 = other_table.col2
FROM
    Table
INNER JOIN
    other_table
ON
    Table.id = other_table.id 

0 个答案:

没有答案