Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Transaction

Author  Topic 

matta0990
Starting Member

44 Posts

Posted - 2011-04-27 : 09:23:04
Im trying to create a transaction that updates a bank account by 10.00 if ran. If the account reaches 100.00 then i want the bank accout to stop adding 10.00 and rollback the transaction. I can get it to all the 10.00 everytime the query is ran but for some reason it wont stop at 100.00 it just keeps going.

Any ideas?

M Atkinson

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-27 : 09:28:50
Please show the query that you want do change to the new behavio[u]r.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-27 : 09:50:06
begin tran
update account
set bal = bal + 10
if exists (select * from account where bal > 100)
begin
rollback tran
raiserror ('account greater than 100',16,-1)
end
else
commit tran

But I'm pretty sure this isn't what you want.
Why not do the test to see if an account is 90 and not do the update if it is.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -