MySQL Forums
Forum List  »  General

Insert Into Inside an IF statement
Posted by: Jef Dilley
Date: November 09, 2017 01:52PM

I'm running into an error in my stored procedure, and after numerous YT videos and forums, I still have no clue where I'm going wrong. Given what I'm trying to do, it all seems to look correct.

Here's the deal. I take in some information to buy some stock, I use an IF to make sure that I have enough money to make the purchase, I then insert the purchase information into my TRADES table and update the cash balance in ACCOUNTS to reflect the spending of $$.

I can't even test to see if it works correctly because it won't run. The only error I'm getting is at INSERT INTO, in which it says error: INTO (into) is not valid input at this position

I have done ALL of my insert statements the exact same way, and have no idea why this particular syntax is incorrect? Any help would be greatly appreciated!




CREATE PROCEDURE `BUY` (TID INT,ID INT, CASH INT, T_NAME VARCHAR(4) , TCOUNT INT, TBUYDATE DATE, TBUYPRICE INT )

BEGIN

IF ( ACCOUNT.CASH_BALANCE >= (TCOUNT * TBUYPRICE),

INSERT INTO TRADES (TRADE_ID, ACCOUNT_ID, TRADE_NAME, TRADE_COUNT, TRADE_BUYDATE, TRADE_BUYPRICE)

VALUES (TID, ID, T_NAME, TCOUNT, TBUYDATE, TBUYPRICE)

AND UPDATE ACCOUNT.CASH_BALANCE

WHERE ACCOUNT.ACCOUNT_ID = ID
SET ACCOUNT.CASH_BALANCE = (ACCOUNT.CASH_BALANCE - (TCOUNT * TBUYPRICE)),

#no insert

);

END IF;

Options: ReplyQuote


Subject
Written By
Posted
Insert Into Inside an IF statement
November 09, 2017 01:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.