/*
将游标定以在字串里,例如:
*/declare @name sysname-- 将游标 Cursor_Test 定义在字串里:
exec sp_executesql N'declare Cursor_Test cursor for select top 10 name from sysobjects'open Cursor_Test
fetch next from Cursor_Test into @namewhile @@fetch_status = 0
begin
print @name
fetch next from Cursor_Test into @name
endclose Cursor_Test
deallocate Cursor_Test
将游标定以在字串里,例如:
*/declare @name sysname-- 将游标 Cursor_Test 定义在字串里:
exec sp_executesql N'declare Cursor_Test cursor for select top 10 name from sysobjects'open Cursor_Test
fetch next from Cursor_Test into @namewhile @@fetch_status = 0
begin
print @name
fetch next from Cursor_Test into @name
endclose Cursor_Test
deallocate Cursor_Test
第一处错误的地方可以这样改,第二处楼主参照修改,谢谢:
*/SET @SQLText='DECLARE Cur_Typeid CURSOR Scroll for SELECT DISTINCT typeid FROM '+ @TableNameFrom
exec sp_executesql @SQLText
open Cur_Typeid
...