January 28, 2006 at 8:56 pm
It only seems to rollback after the value in the record is already -0
for example if the balance in record is 500 and we subtract 1000, it does not rollback. but the next time when the balance is -500, it rolls back. can someone help and tell me what i am doing wrong.
thanx!
Declare @Balance Money
Begin transaction
Update Table1
set @Balance = Balance = Balance - 1000
where AccNo = '13245669'
If @Balance => 0
Begin
Commit Transaction
Else
Begin
Rollback Transaction
End
January 29, 2006 at 2:23 am
Why not simply do:
Update Table1
set Balance = Balance - 1000
where AccNo = '13245669'
and Balance >= 1000
January 29, 2006 at 10:39 pm
January 30, 2006 at 1:39 pm
A "begin transaction" statement does not require an "end"
The following works but I agree that its best to do the update by qualifying the balance in the where clause.
create table table1 (Balance Money, AccNo varchar(20))
insert table1 values(500, '13245669')
Declare @Balance Money
Begin transaction
Update Table1
set @Balance = Balance = Balance - 1000
where AccNo = '13245669'
If @Balance >= 0
Begin
Commit Transaction
end
Else
Begin
Rollback Transaction
End
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply