declare @MXId int
declare @WHId int
declare @ProductCount float
declare @ProductId int
--声明游标
DECLARE UPDATE_WH_E_CURSOR CURSOR FOR SELECT [id],[WHId],[ProductCount],[ProductId] FROM tbl_SalesTicketMX WHERE [STId] = @getSourceId
--打开游标
OPEN UPDATE_WH_E_CURSOR
--循环读取
FETCH NEXT FROM UPDATE_WH_E_CURSOR INTO @MXId,@WHId,@ProductCount,@ProductId
--如果一直有数据
WHILE (@@FETCH_STATUS=0)
BEGIN
--执行操作...
UPDATE tbl_WHPToWH SET ActualCount = ActualCount - @ProductCount , VirtualCount = VirtualCount -@ProductCount where ( [SourceId ] = @ProductId ) AND ([WHId] = @WHId)
fetch next from UPDATE_WH_E_CURSOR INTO @MXId,@WHId,@ProductCount,@ProductId
END
--关闭游标
CLOSE UPDATE_WH_E_CURSOR
--删除游标
DEALLOCATE UPDATE_WH_E_CURSOR