我定义了一个游标,但这个游标执行后,却怎么都没有发生作用。
游标如下:DECLARE AAA CURSOR DYNAMIC
FOR
select item_no from base_entry_message where item_no like 'PK%'
FOR UPDATE OF item_no
OPEN AAADECLARE @ID int,@item_no1 char (25)
set @ID = 1
set @item_no1 = ' '
FETCH next FROM AAA into @item_no1
while @@cursor_rows = 0
begin
update base_entry_message set item_no = 'PK' + Replace(space(11 - len(@ID)),' ','0') + @ID where CURRENT of AAA
set @ID = @ID + 1
FETCH next FROM AAA into @item_no1
end
CLOSE AAA
DEALLOCATE AAA
感觉是 while @@cursor_rows = 0 这个错了,我又不知道该如何写才是对的,哪位兄弟帮帮我吧。
游标如下:DECLARE AAA CURSOR DYNAMIC
FOR
select item_no from base_entry_message where item_no like 'PK%'
FOR UPDATE OF item_no
OPEN AAADECLARE @ID int,@item_no1 char (25)
set @ID = 1
set @item_no1 = ' '
FETCH next FROM AAA into @item_no1
while @@cursor_rows = 0
begin
update base_entry_message set item_no = 'PK' + Replace(space(11 - len(@ID)),' ','0') + @ID where CURRENT of AAA
set @ID = @ID + 1
FETCH next FROM AAA into @item_no1
end
CLOSE AAA
DEALLOCATE AAA
感觉是 while @@cursor_rows = 0 这个错了,我又不知道该如何写才是对的,哪位兄弟帮帮我吧。
这句话通不过吧?应该为:
update base_entry_message set item_no = 'PK' + Replace(space(11 - len(@ID)),' ','0') + rtrim(@ID) where CURRENT of AAA你再看一下select item_no from base_entry_message where item_no like 'PK%'是你要更新的结果集吗?
这句我已经用cast改过来了,查询出来,就是最后一条记录没有更新。其它的记录都OK了。