将值从一列插入另一个表中的另一列

时间:2017-08-18 13:09:11

标签: sql tsql

请有人协助,

我有两个表,Item表和包含许多行的Import表

我需要将Import.Price插入Item.BuydownPrice

其中import.barcode = item.itemlookupcode

亲切的问候

2 个答案:

答案 0 :(得分:1)

这听起来像是令人困惑的概念。将值从一个表的列插入到另一个表的列中非常简单。但是,在这种情况下,where条件没有多大意义。

听起来我(但请告诉我,如果我错了)您尝试使用加入Price列添加到Item表格中:

select a.*, b.Price as BuyDownPrice
from item a
left join import b
  on a.itemlookupcode = b.barcode

答案 1 :(得分:0)

update a

 set a.BuydownPrice = b.Price
FROM         BuydownPrice AS a INNER JOIN
                      Item AS b ON a.barcode = b.itemlookupcode