1,
create function getstr(@id Nchar(4000))
returns Nvarchar(4000)
as
begin
declare @str Nvarchar(2000)
set @str=N''
select @str=@str+rtrim(bill)+N',' from b
where 编码=@id
if @str<>N''
set @str=left(@str,len(@str)-1)
return @str
end
GO
2,
select 编码,dbo. getstr( getstr) as 名称 from a group by 编码
create table table_1 ( i int , o int)
create table table_2 ( i int , h int)
create table table_3 ( h int , m varchar(4))
create function get_n (@i int)
returns varchar(800)
as
begin
declare @str varchar(800)
select @str =''
select @str =@str + table_3.m from table_2 ,table_3 where table_2.i=@i and table_2.h = table_3.h
return @str
end