请教一个题 求助
表 A
------------------
id CS
--------------------
1 我
--------------------
2 是
--------------------
3 一
-------------------
4 名
---------------------
5 学生
输出一行结果为:
我是一名学生
--------------------------
(不要用游标的 游标的懂了)
表 A
------------------
id CS
--------------------
1 我
--------------------
2 是
--------------------
3 一
-------------------
4 名
---------------------
5 学生
输出一行结果为:
我是一名学生
--------------------------
(不要用游标的 游标的懂了)
SELECT GROUP_CONCAT(CS) FROM tb
sql server就是行专列
select 'Wo' union all
select 'Shi' union all
select 'Yi' union all
select 'Ming' union all
select 'Xue' union all
select 'Sheng'declare @str nvarchar(500);
set @str='';select @str=@str+name+'+' from @tb;
select Left(@str,len(@str)-1);
declare @表A table(id int,CS nvarchar(5))
insert into @表A
select 1,'我' union all
select 2,'是' union all
select 3,'一' union all
select 4,'名' union all
select 5,'学生' --语句
declare @id int
declare @Result nvarchar(20)
set @id=1
set @Result=''
while(@id<=5)
begin
select @Result=@Result+CS from @表A where id=@id
set @id=@id+1
end
select @Result--结果
--------------------
我是一名学生(1 行受影响)
set @Result=''
select @Result=@Result+CS from @表A
select @Result--结果
--------------------
我是一名学生
set @Result=''
select @Result=@Result+CS from @表A
select @Result支持这种写法,顶一顶