详细内容
SQL Server里编写的自定义函数,并包含游标
发布日期:2010-05-25     点击:3553     字体:[ ]

--传入字符串参数,返回字符串
CREATE FUNCTION PMselect(@pProID nvarchar(40))
RETURNS nvarchar(50) AS 
BEGIN
declare @pList nvarchar(50)
declare @pm nvarchar(10)
--定义游标
declare pm_cursor  cursor  for
 select PersonName from TblPerson where OID in (select User_ID from TblProManager where Pro_ID=@pProID)

--打开游标,获取内容存入@pm
open pm_cursor
fetch next from pm_cursor into @pm
set @pList=''

--如果有数据就循环
while @@FETCH_STATUS =0
begin
if(@pList = '')
set @pList= @pm
else
set @pList=@pList+',' + @pm
fetch next  from pm_cursor  into @pm

end

--关闭游标
close pm_cursor
deallocate pm_cursor

--返回结果
return @pList


END

用户评论
昵称 
内容  *
验证码   
   
相关文章 更多...  
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号 可人软件设计