Solved

Writing script in MySQL Workbench SQL Editor

Posted on 2010-09-16
1
1,415 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
ID: 33697682
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

19 Experts available now in Live!

Get 1:1 Help Now