samedi 28 octobre 2017

If /ELse In SQL Using Parameter to distinguish a Percentage to be added to Value Column

I am trying to write a SQL stored procedure using If/Else that takes the Integer from IncPercent as a parameter and IF the IncPercent is under 10 treats that as a percentage to be added to the value column on OrderDetails table. ELSE if it is 10 or above it only adds 10 percent to the value column on OrderDetails table.

    Create Procedure spAddPercentage
    (
    @IncPercent int
    )
    AS
    BEGIN 
    IF ( @IncPercent < 10 ( SELECT Value From OrderDetails)
    UPDATE Value from OrderDetails
    THEN SUM([Value] * @IncPercent / 100 + Value)
    END IF
    ELSE ( @IncPercent > 10 ( SELECT Value FROM OrderDetails)
    UPDATE Value FROM OrderDetails 
    THEN  Value * 1.1
    END ELSE
    END

Aucun commentaire:

Enregistrer un commentaire