Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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 2008 - Fatal编程技术网

Sql 将多个表的多列添加到一列中

Sql 将多个表的多列添加到一列中,sql,sql-server-2008,Sql,Sql Server 2008,我有两个具有相同列名的表,我必须为这两个表上的某些特定条件添加oprId列值 表1 something oprId abc 1 qwe 2 表2 something oprId abc 2 qwe 5 结果应该是 oprId 3 7 结果: oprId ------ 3 7 我认为你遗漏了问题的重要部分。3和7从何而来?它应该是oprId 1+2和2+5Ok的和。那么您将xyz加入abc和ghj加入qwe?

我有两个具有相同列名的表,我必须为这两个表上的某些特定条件添加oprId列值

表1

something  oprId

abc          1
qwe          2
表2

something  oprId

abc          2
qwe          5 
结果应该是

oprId
3
7
结果:

oprId
------
3
7

我认为你遗漏了问题的重要部分。3和7从何而来?它应该是oprId 1+2和2+5Ok的和。那么您将
xyz
加入
abc
ghj
加入
qwe
?这些值是查询的参数吗?对不起,我现在已经编辑了这个问题
declare @T1 table (something varchar(3), oprId int)
declare @T2 table (something varchar(3), oprId int)

insert into @T1 values ('abc', 1),('qwe', 2)
insert into @T2 values ('abc', 2),('qwe', 5)

select T1.oprId+T2.oprId as oprId
from @T1 as T1
  inner join @T2 as T2
    on T1.something = T2.something
oprId
------
3
7