急问!字符串列相加怎么实现!
ID STATUS
49 Y1
49 Y2
50 Y3
49 Y4
ID 49 相加得到 Y1Y2Y4
怎么实现 谢谢!!
------解决方案--------------------create table t
(ID id, STATUS varchar(10))
insert into t
select 49, 'Y1 ' union all
select 49, 'Y2 ' union all
select 50, 'Y3 ' union all
select 49, 'Y4 '
create function aa(@id int)
returns varchar(100)
as
begin
declare @s varchar(100)
set @s= ' '
select @s=@s+status from t where id=@id
return @s
end
select id,dbo.aa(id) from t group by id
id
----------- ----------------------------------------------------------------
49 Y1Y2Y4
50 Y3
(2 row(s) affected)