Z dokumentacji:DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements.
Aktualizacja
Oto coś bliższego. Musisz uporządkować składnię CONVERT
co jest inne w MySQL.
DELIMITER $$
CREATE PROCEDURE test()
BEGIN
DECLARE dateInsert DATETIME;
SET dateInsert = '1900-01-01';
WHILE dateInsert < '2100-01-01' DO
BEGIN
INSERT INTO DateLookup
(
DateKey, DateFull, FullYear,
QuarterNumber, WeekNumber, WeekDayName,
MonthDay, MonthName, YearDay,
DateDefinition,
CharacterDate,
WeekDay,
MonthNumber
)
SELECT
CONVERT(VARCHAR(8), dateInsert, 112), dateInsert, YEAR(@Date),
DATEPART(qq, dateInsert), DATEPART(ww, dateInsert), DATENAME(dw, dateInsert),
DATEPART(dd, dateInsert), DATENAME(mm, dateInsert), DATEPART(dy,@Date),
DATENAME(mm, dateInsert) + ' ' + CAST(DATEPART(dd, dateInsert) AS CHAR(2)) + ',
' + CAST(DATEPART(yy, dateInsert) AS CHAR(4)),
CONVERT(VARCHAR(10), dateInsert, 101),
DATEPART(dw, dateInsert),
DATEPART(mm, dateInsert)
SET dateInsert = DATEADD(dd, 1, dateInsert)
END
END WHILE;
END $$