~~~~~~~~~~~~~~~的果,sql句怎?
表有一些:
10 10:50的火
11 null
12 null
13 null
14 null
15 null
16 得打提醒下火
16 test
16 tt
16 笑
17 sdfdsf
部怎示成:
10 10:50的火
11 null
12 null
13 null
14 null
15 null
16 1,得打提醒下火;2,test;3,tt;4,笑;
17 sdfdsf
!
[解决办法]
drop table tbtest
go
create table tbtest(name varchar(10),value varchar(20))
insert into tbtest
select '10 ', '10:50的火 '
union all select '11 ',null
union all select '12 ',null
union all select '13 ',null
union all select '14 ',null
union all select '15 ',null
union all select '16 ', '得打提醒下火 '
union all select '16 ', 'test '
union all select '16 ', 'tt '
union all select '16 ', '笑 '
union all select '17 ', 'sdfdsf '
alter function dbo.uf_getstr(@name varchar(10))
returns varchar(8000)
as
begin
declare @str varchar(8000)
set @str= ' '
select @str=@str+isnull(value, ' ')+ '; ' from tbtest where name=@name
select @str=left(@str,len(@str)-1)
return @str
end
select distinct name,dbo.uf_getstr(name) value from tbtest
/*
name value
---------- ------------------------------------
10 10:50的火
11
12
13
14
15
16 得打提醒下火;test;tt;笑
17 sdfdsf
(所影响的行数为 8 行)
*/