使用映射表从多个联接更新表列

时间:2017-06-06 06:33:35

标签: sql-server inner-join

我有三张桌子:a,b,c。表b是a和c的映射表。我正在尝试更新table a column = table c列。

实施更新时,收到错误:

  

[S0001] [4104]无法绑定多部分标识符

UPDATE table_a
SET table_a.Sector = table_c.Sector
FROM table_a
INNER JOIN table_b
  ON table_a.business_ID = cast(table_b.business_id as BIGINT)
INNER JOIN table_c
  ON table_b.ACARA_SML_ID = table_c.ACARA_SML_ID
WHERE a.State = 'ABC';

我感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

直接从SELECT子句使用UPDATE语句:

 UPDATE table_a SET table_a.Sector = C.Sector
 FROM table_c C
 WHERE EXISTS
 ( SELECT 1 FROM table_b B B.ACARA_SML_ID = C.ACARA_SML_ID AND 
              table_a.business_ID = CAST(B.business_id AS BIGINT)
 ) AND A.[STATE] = 'ABC'

答案 1 :(得分:0)

在您使用WHERE的{​​{1}}子句中,此处a.State未设置为任何表的表别名。

您可以使用正确的表别名尝试此查询:

a