sql自定義函數 包含遊標
时间:2010-09-21 来源:人生无聊
--传入字符串参数,返回字符串
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
相关阅读 更多 +