您的位置:首页 > 其它

怎样在存储过程中动态的使用表名,而又可以使用游标?

2008-07-17 09:36 363 查看
--过程
create proc mypro
as
declare @a nvarchar(100),@tbname nvarchar(100)
set @tbname='sysobjects'
exec ('declare mycursor cursor for select name from '+@tbname+' where xtype=''U''')
open mycursor
fetch next from mycursor into @a
while @@fetch_status=0
begin
print @a
fetch next from mycursor into @a
end
close mycursor
deallocate mycursor
go

--执行
exec mypro
--删除过程
drop proc mypro
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: