当前位置:首页 » 编程语言 » sql将两列合并
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql将两列合并

发布时间: 2022-09-15 14:35:21

‘壹’ sql两列合并

试试看!

select cast(sid as varchar(max))+':'+cast(AllotSID as varchar(max)) as bane from PAS_AllotRatio

‘贰’ sql 两列合并成一列的问题

-- a b 类型为varchar
declare @t1 table(a varchar(10),b varchar(10))
insert into @t1
select '1','1' union
select '2','2' union
select '3','3'

select a+b c from @t1

--a b类型为int
declare @t2 table(a int,b int)
insert into @t2
select 1,1 union
select 2,2 union
select 3,3

select cast(a as varchar)+cast(b as varchar) c from @t2

--结果如下:
(3 个资料列受到影响)
c
--------------------
11
22
33

(3 个资料列受到影响)

(3 个资料列受到影响)

c
------------------------------------------------------------
11
22
33

(3 个资料列受到影响)

‘叁’ SQL 将两列的数据合并在一列

selectxxaszzfrom表unionallselectyyfrom表;

‘肆’ sql,把两个表中的两列数据合到一个表中

两个表的数据量一样的吗?
合并后创建新表吗?
需要借助辅助列
select
identity(int,1,1)
as
guid
,val
into
#1
from
table1
select
identity(int,1,1)
as
guid
,val
into
#2
from
table2
select
a.val
as
val1,b.val
as
val2
into
table3
from
#1
a
inner
join
#2
b
on
a.guid
=
b.guid

‘伍’ SQL 两列合并的问题

改为

select isnull(convert(varchar(30),A.a,120),'')+isnull(convert(varchar(30),B.b,120)AS time,'')

‘陆’ SQL怎样合并表中两列的值为一列来显示

select concat(name,id) as nameid,age

from example

具体可以参考:网页链接