问题:
In SQL Server , it's possible to insert into a table using a SELECT statement: 在SQL Server中 ,可以使用SELECT语句insert表中:
INSERT INTO Table (col1, col2, col3)
SELECT col1, col2, col3
FROM other_table
WHERE sql = 'cool'
Is it also possible to update via a SELECT ? 是否还可以通过SELECT 更新 ? I have a temporary table containing the values, and would like to update another table using those values. 我有一个包含这些值的临时表,并想使用这些值更新另一个表。 Perhaps something like this: 也许是这样的:
UPDATE Table SET col1, col2
SELECT col1, col2
FROM other_table
WHERE sql = 'cool'
WHERE Table.id = other_table.id
解决方案:
参考一: https://stackoom.com/question/9nMe/如何从SQL-Server中的SELECT更新参考二: https://oldbug.net/q/9nMe/How-do-I-UPDATE-from-a-SELECT-in-SQL-Server
来源:oschina
链接:https://my.oschina.net/stackoom/blog/3210341
