phpmyadmin 我想增加或减少Total_Crédit中的金额,该金额是Credit_electrecité中的金额,具体取决于要完成的事件

bmp9r5qi  于 2022-11-09  发布在  PHP
关注(0)|答案(2)|浏览(107)
create PROCEDURE PR_Credit_Total(
    in newidpiece int,
    in newnpiece bigint,
    in newnop varchar(60),
    in newdateengagement date,
    in newdatefacture date,
    in newlocalité varchar(50),
    in newtournee int,
    in newnpolice bigint,
    in newservice varchar(20),
    in newmontant float,
    in newecheance varchar(7),
    in newcreated varchar(25),
    in eventvarchar(100)
)
BEGIN
    set @total=(SELECT sum(Total_Crédit) from credit_electricité) ;
    if event=='ajouter' 
    and newtournee is null
        THEN
        if @total-newmontant>=0

                INSERT into vignetteoneep VALUES(newidpiece,newnpiece,newnop,newdateengagement,
                newdatefacture,newlocalité,newtournee,newnpolice,newservice,newmontant,newecheance,newcreated);
                then 
                UPDATE credit_electricité set Total_Crédit=Total_Crédit-newmontant;
        end if;
    end if;

结束

3npbholx

3npbholx1#

create PROCEDURE PR_Credit_Total(
    @newidpiece AS int,
    @newnpiece AS bigint,
    @newnop AS varchar(60),
    @newdateengagement AS date,
    @newdatefacture AS date,
    @newlocalité AS varchar(50),
    @newtournee AS int,
    @newnpolice AS bigint,
    @newservice AS varchar(20),
    @newmontant AS float,
    @newecheance AS varchar(7),
    @newcreated AS varchar(25),
    @event AS varchar(100),
    @total AS INT
)
AS
BEGIN
    set @total=(SELECT sum(Total_Crédit) from credit_electricité)
    if @event = 'ajouter' and @newtournee is null

        if @total - @newmontant >=0

                INSERT into vignetteoneep VALUES(newidpiece,newnpiece,newnop,newdateengagement,
                newdatefacture,newlocalité,newtournee,newnpolice,newservice,newmontant,newecheance,newcreated)

                UPDATE credit_electricité set Total_Crédit=Total_Crédit - @newmontant
END
yh2wf1be

yh2wf1be2#

以下是要修复的语法错误列表
在eventvarchar(100)中缺少空格,应该在event varchar(100)中,但event是关键字,最好避免
如果event=='ajouter'在mysql中为空安全等于〈=〉,那么应该是如果event〈=〉'ajouter',但是=可以
第二个如果没有,那么不清楚插入和更新是否应该是相同条件的一部分,但我怀疑不是

if @total-newmontant>=0 then

            INSERT ...
     else  
            UPDATE ...
    end if;

您可能需要设置分隔符

相关问题