使用游标逐行更新数据

/**//*scroll表示可随意移动游标指        针(否则只能向前),dynamic表示可以读写游标(否则游标只读)*/

         declare @idoc int,@doc varchar(2000)
         set @doc='<NewDataSet>
           <Reserve>
            <key_seq>70373381</key_seq>
                    <type>AP</type>
            </Reserve>
            <Reserve>
            <key_seq>70373380</key_seq>
                   <type>BP</type>
            </Reserve>
           <Reserve>
            <key_seq>70373379</key_seq>
                    <type>CP</type>
            </Reserve>
            </NewDataSet>'

         exec sp_xml_preparedocument @idoc OUTPUT, @doc
         select * into #reserve from openxml (@idoc, '/NewDataSet/Reserve',2)
         with (key_seq nvarchar(20),type nvarchar(20))
           declare  @key_seq varchar(20),@type varchar(20)
         declare my_cursor cursor   for  select * from #reserve
         open my_cursor
          fetch next from my_cursor into @key_seq,@type
          while(@@fetch_status=0)
          begin
          update #reserve set type='MP'  where key_seq=@key_seq
 fetch next from my_cursor into @key_seq,@type
          end     

          close my_cursor
          deallocate my_cursor

         select * from #reserve
         drop table  #reserve

posted @ 2009-03-20 11:04  SpringX  阅读(423)  评论(0编辑  收藏  举报