日期:2014-05-18 浏览次数:20548 次
--sql 2000 CREATE FUNCTION dbo.f_str(@id int) RETURNS varchar(8000) AS BEGIN DECLARE @r varchar(8000) SET @r = '' SELECT @r = @r + ',' + Info FROM tb WHERE id=@id RETURN STUFF(@r, 1, 1, '') END GO -- 调用函数 SELECt id, Info = dbo.f_str(id) FROM tb GROUP BY id
------解决方案--------------------
--sql2005 select id, Info=stuff((select ' '+ltrim(Info) from tb a where a.id=tb.id for xml path('')),1,1,'') from tb group by id
------解决方案--------------------
上面2005可以的