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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 procedure?

Author  Topic 

jieex6
Starting Member

2 Posts

Posted - 2008-03-11 : 23:45:46
SET AUTOCOMMIT=0;
START TRANSACTION;



BEGIN TRAN

SELECT `amount`
from myaccounts
where `ID` IN (Select `ID`
from transaction_accounts
where `transactionID`= 4)

IF `amount` > 10;


BEGIN

SELECT `amount`
from myaccounts
where `ID` IN (Select `ID`
from transaction_accounts
where `transactionID`= 4)

UPDATE myaccounts

SET amount = amount - 500

END;

COMMIT;


Hello.. could please anyway point out what im doing wrong here? i think i've got the syntax wrong somwhere..

Basically i query the 'amount' value and if that amount value is greater than 10, i want to update it to a new value.

Any help would be greatly appreciated.
Thanks

nathans
Aged Yak Warrior

938 Posts

Posted - 2008-03-12 : 00:18:17
I'd suggest posting in the MySQL forum over at www.dbforums.com, you might get help faster as sqlteam is mssql focused.

Go to Top of Page

jieex6
Starting Member

2 Posts

Posted - 2008-03-12 : 00:21:56
ok thanks man
still if anyone has a clue let me know
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-03-12 : 21:35:59
In most SQL it would be

UPDATE myaccounts
set amount=amount-500
WHERE
ID in (blah...)
AND amount>10

Don't know about MySQL.
Go to Top of Page
   

- Advertisement -