函数返回多个值

来源:互联网 发布:php pack 16进制 编辑:程序博客网 时间:2024/04/30 07:46
USE [Learnmanager]
GO
/****** Object:  UserDefinedFunction [dbo].[getCount]    Script Date: 02/18/2016 14:23:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[getCount]
(
@id int
)
returns @t table ( ccount int, kcount int)
as
begin
  declare @ccount int,@kcount int;
with nodes
as
(
select * from k_type where parentid=@id
union all 
select child.* from k_type as child,nodes par where child.parentid=par.id
)
select @ccount=COUNT(1) from nodes;


with nodes2
as
(
select * from k_type where id=@id
union all 
select child.* from k_type as child,nodes2 par where child.parentid=par.id
)
select  @kcount=count(1) from k_info where status=1 and typeid in ( select  id from nodes2)


insert into @t(ccount,kcount) select @ccount,@kcount -- values(@ccount,@kcount);
return  ;
 

end


调用方法:

 select * from  dbo.getCount(0) b

0 0
原创粉丝点击