Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在update语句中连接多个表_Sql Server - Fatal编程技术网

Sql server 在update语句中连接多个表

Sql server 在update语句中连接多个表,sql-server,Sql Server,我正在尝试在update语句中连接三个表,但到目前为止没有成功。我知道此查询适用于连接两个表: update table 1 set x = X * Y from table 1 as t1 join table 2 as t2 on t1.column1 = t2.column1 但是,在我的例子中,我需要连接三个表,以便: update table 1 set x = X * Y from table 1 as t1 join table 2 as t2 join table3 as t3

我正在尝试在update语句中连接三个表,但到目前为止没有成功。我知道此查询适用于连接两个表:

update table 1
set x = X * Y
from table 1 as t1 join table 2 as t2 on t1.column1 = t2.column1
但是,在我的例子中,我需要连接三个表,以便:

update table 1
set x = X * Y
from table 1 as t1 join table 2 as t2 join table3 as t3 
on t1.column1 = t2.column1 and t2.cloumn2 = t3.column1
这是行不通的。我还尝试了以下查询:

update table 1
set x = X * Y
from table 1, table 2, table 3
where column1 = column2 and column2= column3

有人知道实现这一点的方法吗

您肯定不想使用
table,table,table
syntax。对于中间代码示例,join语法遵循的规则与
SELECT
的规则大致相同,与
UPDATE
的规则相同<代码>在…上加入t2在…上加入t3无效,但
在…上加入t2。。。在
上加入t3有效

下面是我的建议,尽管它应该更新以完全限定
y
的来源:

UPDATE t1
  SET x = x * y  -- should either be t2.y or t3.y, not just y
  FROM dbo.table1 AS t1
  INNER JOIN table2 AS t2
  ON t1.column1 = t2.column1
  INNER JOIN table3 AS t3
  ON t2.column2 = t3.column1;