Build a store procedure to Update and insert table ?
I have Two tables in my Database called AvaiableBalance and Balancewithdraw.
Lets Execute the Procedure - when balance is available then collect what ever money you want and update and insert same in to tables.
This table(AvaiableBalance ) store the customer Bank balance and A/C details and one more table (Balancewithdraw) store the data when customer withdraw amount from ATM or Bank. this is the two tables history. now when customer with draw balance at ATM at the same time update the table called AvaiableBalance and insert a new Record into Balancewithdraw table. for this problem we going to achive through Store Procedure
Balance withdraw table -
when we with draw amount at that time we insert data into Balancewithdraw table automatically with above values (A/c No, What is the withdraw balance, Withdraw time and date)
Create store procedure-
/************************************************
Sp name :SPwithdraATMStatement
Purpose of sp :it helps to update table(AvaiableBalance) and insert new record in
to Balancewithdraw table
when Sp is Execute
Database :TEST
***********************************************************
History
1. update and Insert two tables
select * from AvaiableBalance
select * from Balancewithdraw
***********************************************************/
CREATE proc SPwithdraATMStatement
@input
money
as
Begin
Declare @time datetime
set @time = GETDATE()
Declare @AV money
select @AV = Avaiable_balance from AvaiableBalance
Declare @Ano nvarchar(20)
select @Ano= [A/c] from AvaiableBalance
if @AV <@input
Begin
print'Insufficient Balance Please Renter the amount'
end
else
Begin
--condition1
print
'collect ur money '+space(3)+cast (@input as varchar)
--condition2
update AvaiableBalance
set
Avaiable_balance = Avaiable_balance-(@input)
--condition3
insert into Balancewithdraw values (@Ano,@input, @time)
End
End
Lets Execute the Procedure - when balance is available then collect what ever money you want and update and insert same in to tables.
check the record inserted or not- same amount inserted into table
Comments