MySQL Forums
Forum List  »  Stored Procedures

If Then Else is not working
Posted by: Jason Wisdom
Date: June 19, 2021 08:02PM

Hi, I apologize for the true newbieness of this question, but I have read 3-4 different pages, am copying what they write verbatim, and still get errors when I execute on my MySqlWorkbench.

I want to execute one of two queries, in a StoredProc, depending on a user's setting.

MySQL version 5.7.23-23

IF (1=1) THEN
select 1;
ELSE
select 2;
END IF

And the "IF" is underlined in red, with the message, ""IF" is not valid at this position, expecting EOF, ALTER, ANALYZE, BEGIN, BINLOG, CACHE, ..."
(Note wrapping the block in an BEGIN and END does not change this message)


I have even tried this:
create procedure spTest()
IF (1=1) THEN
select 1;
ELSE
select 2;
END IF

Here, select 1; has the "1" underlined in red with the message, "Statement is incomplete, expecting ;"


Any thoughts? I just want to run the simplest of IF statements....if user setting is A, run select statement 1. if user setting is B, run select statement 2.

Many thanks,

Options: ReplyQuote


Subject
Views
Written By
Posted
If Then Else is not working
5415
June 19, 2021 08:02PM
1162
June 19, 2021 09:09PM


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.