0

正在使用游标更新我的空列,但它没有更新

Declare @Itemcode as varchar(30)
Declare @SLV as varchar(20)
declare cursor1 cursor for 
Select Itemcode ,U_SLV from  oitm_Clone where sapitem is null and u_slv is null
open cursor1 
  fetch next FROM cursor1 INTO @Itemcode ,@SLV
   WHILE @@FETCH_STATUS = 0
   begin
   if @SLV is null
   begin
   declare @sql1 as varchar(max)        
          set @sql1 = 'Update [dbo].oitm_Clone set sapitem ='''+ @Itemcode +''' where ItemCode='''+ @Itemcode +''' and U_SLV ='''+ @SLV +''''
          print @sql1
          execute (@sql1)
   end
    FETCH NEXT FROM cursor1 INTO @Itemcode ,@SLV
   end
    CLOSE cursor1
DEALLOCATE cursor1
4

2 回答 2

1

我认为您不需要游标来执行此更新。试试这个简单的更新,它与你的光标具有相同的逻辑,性能大大提高。

Update [dbo].oitm_Clone 
Set sapitem = itemcode
Where sapitem is null and u_slv is null
于 2013-09-16T12:01:55.353 回答
0

尝试使用这个

WHILE @@FETCH_STATUS <> -1 

代替

WHILE @@FETCH_STATUS = 0 

希望对你有帮助

问候

于 2013-09-16T11:58:53.863 回答