SQL Update从一个表列到另一个表列的值

时间:2017-01-17 16:27:43

标签: sql sql-server

我有一个简单的select语句,用于标识我想要更新的行。基本上我想将vad_description复制到vb_description并且无法解决这个问题。任何帮助将不胜感激。

    SELECT
  variant_bom.vb_id
 ,variant_bom.vb_description
 ,variant_detail.vad_description
FROM dbo.variant_bom
INNER JOIN dbo.variant_detail
  ON variant_bom.vb_vad_id = variant_detail.vad_id
INNER JOIN dbo.variant_setting
  ON variant_setting.vas_vad_id = variant_detail.vad_id
WHERE variant_setting.vas_manufactured_variant = 1
AND variant_setting.vas_discontinued_product = 0

1 个答案:

答案 0 :(得分:1)

尝试这样的事情

UPDATE vb
SET    vb.vb_description = vd.vad_description
FROM   dbo.variant_bom vb
       INNER JOIN dbo.variant_detail vd
               ON vb.vb_vad_id = vd.vad_id
       INNER JOIN dbo.variant_setting vs
               ON vs.vas_vad_id = vd.vad_id
WHERE  vs.vas_manufactured_variant = 1
       AND vs.vas_discontinued_product = 0 

为表格提供Alias名称将使您的查询更具可读性