我想把下面这段代码写成存储过程,提供MyCorpID,SellNum这2个变量,请问该如何写?'统计已经出入库的数量
Set Rs = Db.ExeCute("Select Sum(Amount_In) as Amount_In From [ACS_Whs_Goods] Where Annul=0 And Chk>1 And CorpID="&MyCorpID&" And LinkNum='"&SellNum&"'")
Whs_In = Rs("Amount_In")
If IsNull(Whs_In) Or Whs_In = "" Then Whs_In = 0
Rs.Close
Db.Execute("Update [ACS_Sell_Goods] Set Amount_In='"&Whs_In&"' Where CorpID="&MyCorpID&" And SellNum='"&SellNum&"'")

解决方案 »

  1.   

    if object_id('SP_TEST') is not null drop procedure SP_TEST
    go
    create procedure SP_TEST
    @MyCorpID int,   --这里的类型要看你自己的定义
    @SellNum int   --这里的类型要看你自己的定义
    as
    begin
    declare @Whs_In int
    Select @Whs_In=Sum(Amount_In)
    From [ACS_Whs_Goods]
    Where Annul=0 And Chk>1 And CorpID=@MyCorpID And LinkNum=@SellNumif @Whs_In is null
    begin
    set @Whs_In=0
    endUpdate [ACS_Sell_Goods]
    Set Amount_In=@Whs_In
    Where CorpID=@MyCorpID  And SellNum=@SellNum
    end
    go
      

  2.   

    我按你的方法写了如下代码:
    if object_id('Stat_Account') is not null drop procedure Stat_Account
    go
    create procedure Stat_Account
    @AccountID int,   --定义接受的参数
    as
    begin
    declare @Totle_Cash_In int
    declare @Totle_Cash_Out int
    Select @Totle_Cash_In=Sum(Money_In),@Totle_Cash_Out=Sum(Money_Out)
    From [ACS_Money]
    Where Annul=0 And Chk>1 And AccountID=@AccountIDif @Totle_Cash_In is null
    begin
        set @Totle_Cash_In=0
    endif @Totle_Cash_Out is null
    begin
        set @Totle_Cash_Out=0
    endUpdate [ACS_Money_Account]
    Set Totle_Cash_In=@Totle_Cash_In,Totle_Cash_Out=@Totle_Cash_Out
    Where AccountID=@AccountID
    end
    go提示错误:
    消息 156,级别 15,状态 1,过程 Stat_Account,第 3 行
    关键字 'as' 附近有语法错误。
    请问该怎么改?