Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Como faço para converter isso de TSQL para MYSQL?


Da documentação:DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements.

Atualizar

Aqui está algo mais próximo. Você precisará classificar a sintaxe para CONVERT que é diferente no 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 $$