sql 两列合并成一列的问题

2025-02-27 06:44:05
推荐回答(3个)
回答1:

用vb调用如下sql语句:

select convert(varchar(1),a)+convert(varchar(1),b) as c from test;

---
以上,希望对你有所帮助。

回答2:

-- 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 个资料列受到影响)

回答3:

insert into test1 select a,b,a+b as c from test
select * from test1