使用连接进行更新

时间:2015-09-14 17:08:22

标签: sql-server tsql

如何在SQL Server中更新此语句?

SELECT *
From std_company
join std_company_receipt 
  on cmp_guid = lcr_cmp_guid
join std_receipt 
  on lcr_rcp_guid = rcp_guid
where cmp_guid = '704BEF57-2740-4E20-B666-60DD25D73DCA';

类似于:

    update std_Receipt
    set rcp_ForceUnitemize = 1
    join std_company_receipt on cmp_guid = lcr_cmp_guid
    join std_receipt on lcr_rcp_guid = rcp_guid
   where cmp_guid = '704BEF57-2740-4E20-B666-60DD25D73DCA'

1 个答案:

答案 0 :(得分:1)

您缺少FROM语句。您还应该对表进行别名,以便与列相关的表没有歧义。我作为副本提交的链接显示了所有这些。

我猜到了自从你离开之后哪些列与哪些表有关。

UPDATE rec
SET rec.rcp_ForceUnitemize = 1
FROM std_Receipt rec
INNER JOIN std_company_receipt comp 
   ON rec.cmp_guid = comp.lcr_cmp_guid
INNER JOIN std_receipt rec2 
   ON rec2.lcr_rcp_guid = comp.rcp_guid
WHERE rec.cmp_guid = '704BEF57-2740-4E20-B666-60DD25D73DCA'