Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.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 是否一次更新整个列?_Sql_Sql Server_Tsql_Sql Update - Fatal编程技术网

Sql 是否一次更新整个列?

Sql 是否一次更新整个列?,sql,sql-server,tsql,sql-update,Sql,Sql Server,Tsql,Sql Update,我在网上搜索,但找不到符合我需要的东西。我正在使用northwind示例数据库 例如,我有excel表格附带的新价格 我作为名为[Product update]的新表导入到我的数据库中,列名与上面的[Product,new Price]相同,现在我想将products表更新为excel表单附带的新价格 我不想写15条更新语句。我相信,这件事必须一次用一条命令完成 我写了这样的东西 update Products set UnitPrice = [Product Updates].[New P

我在网上搜索,但找不到符合我需要的东西。我正在使用northwind示例数据库

例如,我有excel表格附带的新价格

我作为名为[Product update]的新表导入到我的数据库中,列名与上面的[Product,new Price]相同,现在我想将products表更新为excel表单附带的新价格

我不想写15条更新语句。我相信,这件事必须一次用一条命令完成

我写了这样的东西

update Products 
set UnitPrice = [Product Updates].[New Price])
where Products.ProductName=dbo.[Product Updates].Product  

但是它不起作用

一个简单的解决方案使用了一个
连接

update p
    set UnitPrice = pu.[New Price]
    from Products p JOIN
         [Product Updates] pu
         on p.ProductName = pu.Product;

我建议你给事物命名时不要用空格,这样你就不需要使用方括号了。它们只会使查询更难编写和阅读。

您可以对句子进行编码,但不要对代码进行编码。我很久没问任何问题了。我已经习惯于问某事了。你是完美的。谢谢你的建议。但是我有没有问过别人为什么投反对票?我找不到和我儿子一样的东西situation@UfukSURMEN . . . 我不知道为什么这个问题会吸引反对票。它有示例数据、一次查询尝试、正确的标记,所以对我来说似乎是合理的。