title: How to Convert a negative value received through a parameter to positive in the stored procedure code?
body: <p>I have some concerns, I'm creating a stored procedure to work with a cafeteria system. The user on the cafeteria will send me through parameter an employee code and the amount consumed. So I far I have calculated this:</p>
  
  <p>IF @Amount&lt; @Subsidy  (Subsidy being 20 Dollars per day)</p>
  
  <pre><code>BEGIN
  
   UPDATE CreditSub 
     SET Subsidy = Subsidy - @Amount, Fecha = @CurrDate   
    WHERE Code = @Code;
  
  END
  
  
   IF @Amount &gt; @Subsidy (Being credit 100)
  
   BEGIN  
  
     UPDATE CreditSub 
     SET @AmountDif= @Amount - Subsidy, Subsidy= 0, Credit = Credit - @AmountDif,                Date = @CurrDate
     WHERE Code = @Code;
  
   END
  </code></pre>
  
  <p>What I'm basically doing is a calculation that if the user insert less than 20 dollars it will run the first batch if is greater it's going to run the second deducting the 20 dollars of the subsidy plus deducting the rest of the credit (being 100 Dollars). </p>
  
  <p>Now, if the user cancels the order, the value returned to me will be a negative value like "If the employee orders 70 dollars of food, then the order must be cancelled, the system will return -70 which I need to take and summarize part of it to the subsidy and part of it to the credit if the subsidy was not spent on that day. How do I split the values or rollback the last transaction converting the negative to positive?. Please ask me any questions, I need help here with this. </p>
  
  <p>Thanks a billion!</p>