游标的定义

来源:互联网 发布:数据交换平台 中软 编辑:程序博客网 时间:2024/05/01 23:01
 

游标
Declare @Name varchar(40)
Declare Cur Cursor For Select b.name from syscolumns a ,sysobjects b where a.id = b.id and a.name = 'custcode'

Open Cur
Fetch next From Cur Into @Name
While @@fetch_status=0  
Begin
  exec ('select * from ' + @Name)
  Fetch Next From Cur Into @Name
End  
Close Cur  
Deallocate Cur

原创粉丝点击