标题:求助,网上找的MSSQL的先进先出例子,谁能帮助改写成MYSQL的,谢谢!
只看楼主
小宜
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-11-29
 问题点数:0 回复次数:0 
求助,网上找的MSSQL的先进先出例子,谁能帮助改写成MYSQL的,谢谢!
create proc wsp
@name varchar(50),--商品名称
@cost int         --销售量
as
--先得出该货物的库存是否够
declare @spare float --剩余库存
select @spare=sum(j)-sum(c) from t where name=@name
if(@spare>=@cost)                        
   begin
    --根据入库日期采用先进先出原则对货物的库存进行处理  
     update t set c=                                                                                                                     
     case when (select @cost-isnull(sum(j),0)+isnull(sum(c),0) from t where name=@name and jdate<=a.jdate and j!=c)>=0
     then a.j
     else                        
        case when (select @cost-isnull(sum(j),0)+isnull(sum(c),0) from t where name=@name and jdate<a.jdate and j!=c)<0
        then 0
        else (select @cost-isnull(sum(j),0)+isnull(sum(c),0)+a.c from t where name=@name and jdate<a.jdate and j!=c)
        end
     end
     from t a where name=@name and j!=c
   end
else
    raiserror('库存不足',16,1)   
    return
go
搜索更多相关主题的帖子: 网上 where 销售量 update create 
2016-05-18 07:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464950-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.136276 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved