--创建处理函数
create function f_str(@col1 varchar(10))
returns varchar(8000)
as
begin
declare @ varchar(8000)
set @=''
select @=@+'/'+col3 from tb1 where col1=@col1
return(substring(@,2,8000))
end
go--调用实现查询
select col1,col2=sum(col2),col3=dbo.f_str(col1)
from tb1 group by col1
create function f_str(@col1 varchar(10))
returns varchar(8000)
as
begin
declare @ varchar(8000)
set @=''
select @=@+'/'+col3 from tb1 where col1=@col1
return(substring(@,2,8000))
end
go--调用实现查询
select col1,col2=sum(col2),col3=dbo.f_str(col1)
from tb1 group by col1
declare @ varchar(8000)
create table tb1(col1 varchar(10),col2 int,col3 varchar(10))
insert tb1 select 'a1',1,'c1'
union all select 'a1',2,'c2'
union all select 'a2',3,'c3'
go--创建处理函数
create function f_str(@col1 varchar(10))
returns varchar(8000)
as
begin
declare @ varchar(8000)
set @=''
select @=@+'/'+col3 from tb1 where col1=@col1
return(substring(@,2,8000))
end
go--调用实现查询
select col1,col2=sum(col2),col3=dbo.f_str(col1)
from tb1 group by col1
go--删除测试
drop table tb1
drop function f_str/*--测试结果
col1 col2 col3
---------- ----------- -----------
a1 3 c1/c2
a2 3 c3(所影响的行数为
--*/