Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

MySQL While do Syntax Errors

Good night, i am trying to translate this script into MySQL. In fact, i have made a progress of this little snippet.
Could you please tell me what am i doing wrong?


BEGIN

CREATE TEMPORARY TABLE mydb.VAR001  (
id int,
trainingId int 
);

SET @row_number:=0;
insert into mydb.VAR001 
select @row_number:=@row_number+1 AS row_number, trainingId from mydb.tb_trainingHistoryStatus where userId = 77423 and trainingStatusId = 2 
group by trainingId;

DECLARE MIN INT default 0;
DECLARE MAX INT default 0;


SET MIN := ( SELECT MIN(id) FROM mydb.VAR001 );
SET MAX := ( SELECT MAX(id) FROM mydb.VAR001 );

WHILE ( @MIN < @MAX ) DO
select * from mydb.VAR001
SET @MIN = @MIN+1
END WHILE;



DROP TEMPORARY TABLE mydb.VAR001;

END

Open in new window


1- The tempoarary table could duplicate on execution time because of threads correct?
2- I get an error on the While statement
3- generally i cannot run from BEGIN to END without problems. I get several errors.

Thank you very much for your advice
0
JavierVera
Asked:
JavierVera
1 Solution
 
PortletPaulCommented:
Can you describe what it is you actually want to achieve?

You might not need a temp table at all, but I cannot suggest an alternative without knowing more about the objective.
0
 
JavierVeraAuthor Commented:
Thanks for your help., i have found the issue. What i wanted is to get somewhat like an anonymous block in order to test the while sentence i am building.
So far, i got to run this script from a Java app. And it've worked nicely.
Apart of this, in the snipped i pasted earlier i find that i missed the DECLARE statement wich is NOT at the begginning of the script and this is a must when building procedures.
thanks for your time.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now