exec('
DECLARE authors_cursor CURSOR OPTIMISTIC DYNAMIC FOR
select * from Fcashdocitemt where doccode=@doccode
for update of docitem')
-->试试
DECLARE authors_cursor CURSOR OPTIMISTIC DYNAMIC FOR
select * from Fcashdocitemt where doccode=@doccode
for update of docitem
DECLARE authors_cursor CURSOR OPTIMISTIC DYNAMIC FOR
select * from Fcashdocitemt where doccode=@doccode
for update of docitem')
-->试试
DECLARE authors_cursor CURSOR OPTIMISTIC DYNAMIC FOR
select * from Fcashdocitemt where doccode=@doccode
for update of docitem
@doccode varchar(20)
as
DECLARE @i int,@sql varchar(500)
set @i=0
set @sql=' DECLARE authors_cursor CURSOR OPTIMISTIC DYNAMIC FOR '+
' select * from Fcashdocitemt where doccode='''+@doccode+''''+
' for update of docitem'
exec(@sql)
open authors_cursorfetch first from authors_cursor
while (@@fetch_status=0)begin
select @i=@i+1update Fcashdocitem set [docitem]=@i where
CURRENT OF authors_cursor
fetch next from authors_cursorend close authors_cursordeallocate authors_cursor
在这个事务中你定义了authors_cursor这个局部游标,又使用了另一个事务定义的@doccode变量这样的话,你肯定会出错的啊.你为什么要用动态sql语句呢?觉得不就也OK啊.
create proc mypro
@doccode varchar(20)
as
DECLARE @i int
set @i=0
DECLARE authors_cursor CURSOR OPTIMISTIC DYNAMIC FOR
select * from Fcashdocitemt where doccode=@doccode
for update of docitemopen authors_cursorfetch first from authors_cursor
while (@@fetch_status=0)begin
select @i=@i+1update Fcashdocitem set [docitem]=@i where
CURRENT OF authors_cursor
fetch next from authors_cursorend close authors_cursordeallocate authors_cursor