我在更新表格時遇到問題,並且我確定它的表格非常簡單,但我在此處繞圈轉圈。從日期匹配的select語句更新多個值的表格
表「表1」的數據我想更新的格式如下:
[Month] Figure
----------------------------------
2010-05-01 00:00:00.000 1.0000
2010-06-01 00:00:00.000 1.0000
2010-07-01 00:00:00.000 1.0000
2010-08-01 00:00:00.000 1.0000
表「數據1」包含已更新的數據格式如下:
[Month] Figure
----------------------------------
2010-05-01 00:00:00.000 0.7212
2010-08-01 00:00:00.000 1.2351
的SQL我」 m使用和錯誤信息如下。
UPDATE t1
SET t1.figure = (SELECT figure from data1)
FROM table1 t1 JOIN data1 d1
ON (t1.[month] = d1.[month])
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
我需要一個while循環來遍歷每一行嗎?
祝最終結果是,如下所示:
[Month] Figure
----------------------------------
2010-05-01 00:00:00.000 0.7212
2010-06-01 00:00:00.000 1.0000
2010-07-01 00:00:00.000 1.0000
2010-08-01 00:00:00.000 1.2351
十分讚賞。
@Lieven:謝謝你的回答。它幫助解決我的問題:http://www.leniel.net/2011/08/update-select-sql-server-image-column.html – 2011-08-06 16:44:57
@Lieliel Macaferi - 現在這是我第一次在博客。我要打印這張照片並放在我的牀上:) – 2011-08-07 10:15:27