22,209
社区成员
发帖
与我相关
我的任务
分享
create table A(sn1 int, contect1 varchar(10))
create table B(sn2 int, contect2 varchar(10))
insert into a values(1 , '你好')
insert into a values(2 , '很好')
insert into a values(3 , '一般情况')
insert into a values(4 , '是还可以')
insert into a values(5 , '确实不错')
insert into b values(1 , '可以的')
insert into b values(2 , '你好嘛')
create table c(help varchar(100))
go
declare @output1 varchar(8000)
select @output1 = coalesce(@output1 + '/' , '') + contect1 from a
declare @output2 varchar(8000)
select @output2 = coalesce(@output2 + '/' , '') + contect2 from b
insert into c values( @output1 + '/' + @output2)
select * from c
drop table a , b , c
/*
help
----------------------------------------------------------------------------------------------------
你好/很好/一般情况/是还可以/确实不错/可以的/你好嘛
(所影响的行数为 1 行)
*/
create table A(sn1 int, contect1 varchar(10))
create table B(sn2 int, contect2 varchar(10))
insert into a values(1 , '你好')
insert into a values(2 , '很好')
insert into a values(3 , '一般情况')
insert into a values(4 , '是还可以')
insert into a values(5 , '确实不错')
insert into b values(1 , '可以的')
insert into b values(2 , '你好嘛')
go
declare @output1 varchar(8000)
select @output1 = coalesce(@output1 + '/' , '') + contect1 from a
declare @output2 varchar(8000)
select @output2 = coalesce(@output2 + '/' , '') + contect2 from b
print @output1 + '/' + @output2
drop table a , b
/*
你好/很好/一般情况/是还可以/确实不错/可以的/你好嘛
*/
DECLARE @re VARCHAR(8000);
SET @re='';
SELECT
@re=@re+contect1+'/'
FROM tbA
SELECT
@re=@re+conect2+'/'
FROM tbB
SET @re=LEFT(@re,LEN(@re)-1);
SELECT @re