CREATE FUNCTION 名称(@ID VARCHAR(10))
RETURNS varchar(8000)
AS
BEGIN
declare @i int,@ret varchar(8000)
declare @t table(ID VARCHAR(10),PID VARCHAR(10),Level INT)
set @i = 1
insert into @t select CategoryID,ParentCategoryID,@i from Category where CategoryID = @ID
while @@rowcount<>0
begin
set @i = @i + 1
insert into @t
select
a.CategoryID,a.ParentCategoryID,@i
from
Category a,@t b
where
a.CategoryID=b.PID and b.Level = @i-1
end
select @ret = isnull(@ret,'')+ID+',' from @t order by Level
return @ret
END
create function f_qry2(
@xtype nvarchar(2)
)returns @re table(id int,name sysname)
as
begin
insert @re select id,name from sysobjects where xtype=@xtype
return
end
go
--调用
select * from f_qry2('U')
go
drop function f_qry2
--1.直接从select中返回
create function f_qry1(
@xtype nvarchar(2)
) returns table
as
return(select * from sysobjects where xtype=@xtype) go --调用 select * from f_qry1('U') go drop function f_qry1
@xtype nvarchar(2)
)returns @re table(id int,name sysname)
as
begin
insert @re select id,name from sysobjects where xtype=@xtype
return
end
go
--调用
select * from f_qry2('U')
go
drop function f_qry2
--1.直接从select中返回
create function f_qry1(
@xtype nvarchar(2)
) returns table
as
return(select * from sysobjects where xtype=@xtype) go --调用 select * from f_qry1('U') go drop function f_qry1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。