--合并函数
create function f_merg(@content int)
returns varchar(8000)
as
begin
declare @str varchar(8000)
set @str=''
select @str=@str+','+rtrim(contect) from Mytable where ID=@content
select @str=right(@str,len(@str)-1)
return @str
end
go
--调用:
select ID,contect=dbo.f_merg(ID) from Mytable group by id
/*说明
因为SQL中,字符串的最长长度为8000,所以如果相同id的contect太多的话,会出现显示不完的情况.
*/
|