SQL Merge语句

时间:2012-11-03 09:44:18

标签: sql-server-2008

我正在尝试在SQL Server 2008中使用新的“MERGE”语句。该语句将从temporarty表中获取记录并在其他表中更新。语句如下:

create table #TempTable(ProcPOAmdDel_ProcessAmendmentId bigint,ProcPOAmdDel_SemiFinProdId bigint,ProcPOAmdDel_ChallanQty int)

MERGE PurProcessPOAmendmentDelivery AS pod
USING (SELECT ProcPOAmdDel_ProcessAmendmentId,
       ProcPOAmdDel_SemiFinProdId FROM #TempTable ) AS temp
ON pod.ProcPOAmdDel_ProcessAmendmentId = temp.ProcPOAmdDel_ProcessAmendmentId AND 
   pod.ProcPOAmdDel_SemiFinProdId=temp.ProcPOAmdDel_SemiFinProdId 
WHEN MATCHED THEN UPDATE 
  SET pod.ProcPOAmdDel_ChallanQty = temp.ProcPOAmdDel_ChallanQty;

在运行状态时遇到错误列名无效'ProcPOAmdDel_ChallanQty'。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

在Source表中包含ProcPOAmdDel_ChallanQty列,即temp

MERGE PurProcessPOAmendmentDelivery AS pod
USING (SELECT ProcPOAmdDel_ProcessAmendmentId,
              rocPOAmdDel_SemiFinProdId,
              ProcPOAmdDel_ChallanQty
       FROM #TempTable ) AS temp
ON pod.ProcPOAmdDel_ProcessAmendmentId = temp.ProcPOAmdDel_ProcessAmendmentId AND 
pod.ProcPOAmdDel_SemiFinProdId=temp.ProcPOAmdDel_SemiFinProdId 
WHEN MATCHED THEN 
UPDATE SET pod.ProcPOAmdDel_ChallanQty = temp.ProcPOAmdDel_ChallanQty;