且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sql查询从两个表中添加两列.

更新时间:2022-11-27 15:07:31

update table1 set column1 = column1 + column2 
from table2 where
table2.id = table1.id


查看联合查询

http://www.w3schools.com/sql/sql_union.asp [
Look at Union query

http://www.w3schools.com/sql/sql_union.asp[^]


假设我们有两列,分别来自table1和table2的column1和column2.添加列1和列2并在列1中设置值的SQL查询是什么?

您将需要编写一个 SP 并使用 Cursors 来遍历表的所有行.

其他选择可以是使用表值函数进行相同的操作.
Suppose we have two columns, column1 and column2 from table1 and table2 respectfully. What is the SQL Query to add column1 and column2 and set the value in column1?

You would need to write a SP and use Cursors to loop through all the rows of the table to do it.

Other option can be to use Table Valued Function to do the same.