I want the Update statement to be done when my bit parameter’s value is 1. How can this be achieved?
This is my stored procedure :
CREATE PROCEDURE sp_subBalance @Cost decimal, @userid int, @bit bit output
AS
declare @SubbedBalance decimal, @Currbalance decimal
set @Currbalance = (SELECT User_Balance_tbl.Balance
FROM User_Balance_tbl
WHERE User_Balance_tbl.UserID = @userid)
set @SubbedBalance = (select @Currbalance - @cost)
set @bit = (case when @SubbedBalance > 0 Or @SubbedBalance = 0 then 1 else 0 end)
case when @bit = 1 then (update User_Balance_tbl
set Balance = @SubbedBalance
where User_Balance_tbl.UserID = @userid)
end
It can be done below way: