sql - How to Convert a negative value received through a parameter to positive in the stored procedure code? -


i have concerns, i'm creating stored procedure work cafeteria system. user on cafeteria send me through parameter employee code , amount consumed. far have calculated this:

if @amount< @subsidy (subsidy being 20 dollars per day)

begin   update creditsub     set subsidy = subsidy - @amount, fecha = @currdate      code = @code;  end    if @amount > @subsidy (being credit 100)   begin       update creditsub     set @amountdif= @amount - subsidy, subsidy= 0, credit = credit - @amountdif,                date = @currdate    code = @code;   end 

what i'm doing calculation if user insert less 20 dollars run first batch if greater it's going run second deducting 20 dollars of subsidy plus deducting rest of credit (being 100 dollars).

now, if user cancels order, value returned me negative value "if employee orders 70 dollars of food, order must cancelled, system return -70 need take , summarize part of subsidy , part of credit if subsidy not spent on day. how split values or rollback last transaction converting negative positive?. please ask me questions, need here this.

thanks billion!

break out creditsub 2 tables @code. credit table track credit amount throughout day--positive or negative won't matter. subsidy table populated once per day (or needed) subsidy amount. @ end of day, can math when populate other table. if need know current subsidy amount is, join 2 tables , perform necessary calculation amount.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -