2013-09-16 83 views
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 
+0

這是正確的嗎? 'sapitem ='''+ @Itemcode +'''' –

回答

1

我認爲你不需要光標來做這個更新。試試這個簡單的更新,它具有與光標相同的邏輯,並且性能有了很大的提高。

Update [dbo].oitm_Clone 
Set sapitem = itemcode 
Where sapitem is null and u_slv is null 
0

嘗試使用此

WHILE @@FETCH_STATUS <> -1 

代替

WHILE @@FETCH_STATUS = 0 

希望它會幫你

問候