通过游标动态修改SQL数据库中的价格 通过游标动态修改SQL数据库中的价格

2015-01-07

 

 

 

 --声明一个游标动态修改SQL数据库中的价格

 

 

 

declare MemberPoints_DanJai_cur cursor 
   for select [K_Marketprice],[K_Saleprice],[ID] from  [KNet_CollData] 
go
declare @K_Marketprice decimal(18,2)
declare @K_Saleprice decimal(18,2)
declare @ID varchar(50)
open MemberPoints_DanJai_cur
   fetch next from MemberPoints_DanJai_cur into @K_Marketprice,@K_Saleprice,@ID
    while @@fetch_status=0
       begin
         update [KNet_CollData] set [K_Marketprice]=(select cast(ceiling((rand()*20)+(rand()*10)+(rand()*30)+(rand()*20)+(rand()*1)+(rand()*18)+(rand()*16)+(rand()*14)+(rand()*13)+(rand()*17))+310 as decimal)) where ID=@ID
         fetch next from  MemberPoints_DanJai_cur into @K_Marketprice,@K_Saleprice,@ID
        end

close MemberPoints_DanJai_cur
deallocate MemberPoints_DanJai_cur