想问一下游标里面只有一条记录,需要怎么取?
declare @sums numeric(24, 8)
declare rs1 cursor for
select SUM(delivered_quantity) from tc_deliver_d where deliver_id in (select deliver_id from tc_deliver where account_id=@account_id and deliver_is_valid=1 and is_deleted=0) and prod_id=@product_id and is_deleted=0 and deliver_d_date >= '2012-10-30 00:00:00'
open rs1
fetch next from rs1
into @sums
while @@FETCH_STATUS=0
begin
if(@sums<>@accumulative_stock )
update tc_commercialstock set accumulative_stock=@sums where account_id=@account_id and product_id=@product_id and is_deleted=0
fetch next from rs1 into @sums
end
close rs1
DEALLOCATE rs1
我想问的是,我的rs1里只有一条记录,是不是必须要:
fetch next from rs1
into @sums
while @@FETCH_STATUS=0
来取?
------解决方案--------------------
不是必须的了,你知道只有一笔就可以不用循环了
------解决方案--------------------
也可以这么写,fetch first
fetch first from rs1 into @sums
while @@FETCH_STATUS=0