在SQL Server中使用游标进行更新,但未更新表记录

时间:2019-06-14 09:53:27

标签: sql-server-2008 cursor

我要更新某些表,查询成功执行,但表数据尚未更新

 Declare @DID As Varchar(150);
    Declare @VID As Varchar(150);

    Select @DID = 'D000000000001';

    DECLARE V_cursor CURSOR FOR
      SELECT V_Id
      FROM   V_Table
      Where VNo In ('MP0000001')
      Open V_cursor
      Fetch Next From V_cursor 
                 Into @VID

     While @@FETCH_STATUS = 0
     Begin
     Update a set DId= @DID
       From ATable a 
       Join(Select VId, Vd As AId 
              From VTable
         Union All 
            Select VId, EId 
              From VE
             Where IsCuid=1 
         Union All 
            Select VId, TId 
              From VTTable
             Where TP is not null 
         Union All 
         Select VId, VSubId 
           From VP 
          Where IsCuid=1) q 
             On a.AId = q.AId 
           Where q.VId = @VID
           Fetch Next From V_cursor INTO @VID
         End;
     Close V_cursor;
     DEALLOCATE V_cursor;

请建议我查询中出了什么问题。

0 个答案:

没有答案