Skip to content
Loading
  • 0
    thanks for you
    0
  • 0
    CREATE FUNCTION calculer_montant
    (
    )
    RETURNS DOUBLE
    AS
    BEGIN
    DECLARE @montant_ttc double
    DECLARE @num varchar(200)
    set @montant_ttc= (select sum(brm.Montant) * sum(brm.TVA) from marche m left outer join bon_reception_marche brm on m.Id_marche = brm.Id_marche where Num_marche=@num)
    RETURN @montant_ttc
    END
     
     
    I tried this code but it does not work here are the errors that sends me sql
     
    Msg 156, Niveau 15, État 1, Procédure calculer_montant, Ligne 8
    Syntaxe incorrecte vers le mot clé 'DECLARE'.
    Msg 137, Niveau 15, État 1, Procédure calculer_montant, Ligne 9
    La variable scalaire "@montant_ttc" doit être déclarée.
    Msg 137, Niveau 15, État 2, Procédure calculer_montant, Ligne 10
    La variable scalaire "@montant_ttc" doit être déclarée.
    0
  • Ramesh Barik
    0
    CREATE FUNCTION dbo.calculer_montant
    (
    )
    RETURNS DECIMAL(18,2) -- 
    BEGIN
    DECLARE @montant_ttc decimal(18,2);
    DECLARE @num varchar(200);
    set @montant_ttc= (SELECT
    SUM(brm.Montant) * SUM(brm.TVA)
    FROM marche m
    LEFT OUTER JOIN bon_reception_marche brm
    ON m.Id_marche = brm.Id_marche
    WHERE Num_marche = @num)
    END
    -------------------
     
    Here the @num variable which you are using what should be the value?
     
    I think @num is a parameter which needs to be sent at the time of calling the function.
     If Yes?
     
    Then .. check the below function.
     
    CREATE FUNCTION dbo.calculer_montant
    (
    @num varchar(200)
    )
    RETURNS DECIMAL(18,2)
    BEGIN
    DECLARE @montant_ttc decimal(18,2);
    --DECLARE @num varchar(200);
    set @montant_ttc= (SELECT
    SUM(brm.Montant) * SUM(brm.TVA)
    FROM marche m
    LEFT OUTER JOIN bon_reception_marche brm
    ON m.Id_marche = brm.Id_marche
    WHERE Num_marche = @num)
    END
    0
  • 0
    thanks for you
    0