Solved

Writing script in MySQL Workbench SQL Editor

Posted on 2010-09-16
1
1,408 Views
Last Modified: 2012-06-27
I Have a routine that works but is ginving me an unexpected result.  I'm trying to debug the sql a routine in the MySQL Editor in MySQL Workbench 5.2.16.  I tried taking the SQL from the routine definition and pasting it into the editor.  I added a line at the beginning for my input parameter.  It will not run because of syntax errors.  The DECLARE statements and the IF statements seem to be unacceptable in the editor.  Here I have embedded an image of the editor window that shows the syntax checking.  snapshot of editor windowThe red squgglies indicate syntax errors.

Is there a reference that states what are acceptable sql statements in the editor?
0
Comment
Question by:pbouchard1
1 Comment
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 125 total points
Comment Utility
pbouchard1,

I don't know of a list, but my understanding is that aside from user-defined variables the only valid syntax is those that can execute as a single-line SQL statement which is why IF ... THEN won't work.  You can use case OR if statements as you would in a SQL query though.

Therefore, to test this you can do this.

Instead of:
DECLARE iSeasonYear INTEGER;
SET iSeasonYear = 2010;

Use:
SET @iSeasonYear = 2010;


You can create the variables that are results from queries on the fly using the INTO methodology you already have in place.


For the IF, you would do this in a SELECT.
SELECT CASE WHEN @WeekNum > 0 THEN @WeekNum WHEN ... THEN ... ELSE 17 END AS `WeekNum`

Hope that helps!

Regards,
Kevin
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

9 Experts available now in Live!

Get 1:1 Help Now