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
 Query for transfering money from one account

Author  Topic 

joechungath
Starting Member

1 Post

Posted - 2013-11-29 : 12:13:07
Hi Guys,
I'm new to sql and I desperately need your help.Query for transferring money from one account to another account in same table..so from one account money should be deducted and need to be add into another account.



JC

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-11-29 : 12:19:17
declare @ac1 int = 857
declare @ac2 int = 945
declare @amt = 10

update tbl
set bal = case when ac = @ac2 then bal + @amt when ac = @ac1 then bal - @amt end
from tbl
where ac in (ac1,ac2)




==========================================
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 -