日期:2014-05-18 浏览次数:20576 次
create table ll(Content varchar(50),ID varchar(50)) insert into ll select 'I','24FA5145' insert into ll select 'am','24FA5145' insert into ll select 'Johnny','24FA5145' create function wsp22(@id varchar(50)) returns varchar(1000) as begin declare @sql varchar(1000) select @sql=isnull(@sql+' ','') + Content from ll where id=@id return @sql end select distinct dbo.wsp22(id) as Content,id from ll
------解决方案--------------------
DECLARE @A TABLE(Content VARCHAR(20), ID VARCHAR(20)) insert @A select 'I','24FA5145' UNION ALL SELECT 'am','24FA5145' UNION ALL SELECT 'Johnny','24FA5145' DECLARE @id VARCHAR(20) SET @id='24FA5145' declare @str varchar(8000) set @str='' select @str=@str+' '+Content from @A where id=@id set @str=right(@str,len(@str)-1) SELECT @str AS Content, '24FA5145' AS ID