动态游标
点击次数:22 次 发布日期:2008-11-22 13:41:24 作者:源代码网
|
源代码网推荐
举个例子,你再根据你的具体情况进行修改:
declare @sqlExec varchar(8000),@tableName varchar(255) set @tableName = "sysobjects" set @sqlExec = "declare cursor1 cursor for " + CHAR(13) set @sqlExec = @sqlExec + " select * from " + @tableName exec(@sqlExec) open cursor1 fetch next from cursor1 ---如果要放在变量中请写into <变量列表> while @@fetch_status = 0 ...... fetch next from cursor1 ---如果要放在变量中请写into <变量 end close cursor1 deallocate cursor1
源代码网供稿. |