SQL Server MERGE语句报告无效列

时间:2016-06-28 19:47:48

标签: sql sql-server sql-server-2008 tsql

我有这个MERGE语句在一个数据库服务器上正常工作,我需要将它部署到另一个国家办事处的另一个数据库服务器。我使用了RedGate的SQL Compare,两个数据库都有所需。

MERGE dbo.MfgGrouping AS Target
USING
    (SELECT JC.job_number
         , JC.Quote_NO
         , PMG.MfgGroupingID
         , SR.Description
         , MG.GroupingNumber
         , MG.GroupingDesc
         , MG.Assigned
         , MG.AssignedDate
         , MG.AssignedBy
         , MG.[Priority]
         , P.Record_no
     FROM   dbo.Product AS P
           INNER JOIN dbo.ProductMfgGrouping AS PMG ON P.Record_no = PMG.Record_no
           INNER JOIN dbo.Job_Control AS JC ON P.Quote_NO = JC.Quote_NO
           LEFT OUTER JOIN dbo.MfgGrouping AS MG ON PMG.MfgGroupingID = MG.MfgGroupingID
           LEFT OUTER JOIN dbo.ShopRouting AS SR ON MG.ShopRoutingID = SR.ShopRoutingID
     WHERE  (JC.job_number = @SalesOrder)) AS Source
    ON(Target.MfgGroupingID = Source.MfgGroupingID)

    WHEN MATCHED
       THEN 
          UPDATE 
          SET Target.GroupingNumber = Source.GroupingNumber, 
              Target.Assigned = Source.Assigned, 
              Target.AssignedDate = Source.AssignedDate, 
              Target.AssignedBy = Source.AssignedBy

    WHEN NOT MATCHED BY TARGET
       THEN 
          INSERT(GroupingNumber, Assigned, AssignedDate, AssignedBy, Record_no) 
          VALUES(1, Source.Assigned, Source.AssignedDate, Source.AssignedBy, Source.Record_no);

我遇到的问题是我收到错误:

  

无效的列名'Record_no'

在已部署的数据库上;但不是原来的DB。一切看起来都一样,对我好。

有人可以对此有所了解吗?

唯一的区别是原始数据库是SQL Server 2014,部署的数据库是SQL Server 2008。

谢谢, 麦

enter image description here

0 个答案:

没有答案