我搜索了网页,但无法找到符合我需求的内容。我正在使用northwind示例数据库。
例如,我有excel表附带的新价格。
我导入了我的数据库作为名为[Product Updates]的新表,并且列名与上面的[Product,New Price]相同,现在我想将产品表更新为excel表附带的新价格。
我不想写15个更新语句。它必须在我相信的一个命令的同时完成。
我写了这样的东西
update Products
set UnitPrice = [Product Updates].[New Price])
where Products.ProductName=dbo.[Product Updates].Product
但它不起作用
答案 0 :(得分:3)
一个简单的解决方案使用join
:
update p
set UnitPrice = pu.[New Price]
from Products p JOIN
[Product Updates] pu
on p.ProductName = pu.Product;
我建议你在没有空格的情况下命名,所以你不需要使用方形括号。他们只是让查询更难写和阅读。