日期:2014-05-17 浏览次数:20415 次
select id=stuff((select ','+id from tb t where id=tb.id for xml path('')), 1, 1, '')
from tb
create function dbo.f_str(@id int)
returns varchar(8000)
as
begin
declare @str varchar(8000)
set @str = ''
select @str = @str + ',' + id from tb where id=@id
return stuff(@str, 1, 1, '')
end
go
-- 调用函数 SELECT id = dbo.f_str(id) FROM tb