tags:

views:

44

answers:

1

I am trying to port some code from MS-SQL to MySQL and there is this code that declares a variable and then executes some select statements - it looks like:

USE MarketDB;
GO

DECLARE @Q0 VARCHAR(16);
DECLARE @Q1 VARCHAR(16);
SET @Q0 = '05/30/2008'
SET @Q1 = '08/29/2008'

Now I try to convert this to MySQL and fail totally. Why does the following fail with a syntax error?

DELIMITER ;//

BEGIN
DECLARE Q0 VARCHAR(16);
SET Q0 = '05/30/2008';
END; 
;//
DELIMITER ;

Thanks!

+1  A: 

In MySQL, BEGIN and END are only valid inside stored procedures. Try this for your MySQL translation of your above SQL Server code:

USE MarketDB;
SET @Q0 = '05/30/2008';
SET @Q1 = '08/29/2008';
Asaph
So the declare statements are not necessary in MySQL? In the documentation they do appear. Strange. Thanks a lot! This does seem to work.
Martin Stein
@Martin Stein: For free form SQL statements in MySQL, no need to DECLARE variables. When you get into stored procedures in MySQL, you may encounter DECLARE, DELIMITER, BEGIN, END, etc.
Asaph