Solved

MySQL While do Syntax Errors

Posted on 2014-12-09
2
325 Views
Last Modified: 2014-12-10
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
Comment
Question by:JavierVera
2 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40490274
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
 
LVL 1

Author Comment

by:JavierVera
ID: 40492713
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now