-1
我正在將mssql查詢轉換爲Mysql,但是我得到的錯誤數量比如Declare不在正確的位置,如果ELSE它不在正確的位置。下面是我的SQL查詢:帶DECLARE和IF的MySQl查詢導致錯誤
declare v_StartDateIn varchar(25) default '@1'
declare v_EndDateIn varchar(25) default '@2'
IF (v_StartDateIn = '') OR (v_StartDateIn is null) OR (v_StartDateIn = '$1') THEN SET v_StartDateIn = concat(left(DATE_FORMAT (NOW(), 126),7),'-01T00:00:00');
END IF;
IF (v_EndDateIn = '') OR (v_EndDateIn is null) OR (v_EndDateIn = '$2') THEN SET v_EndDateIn = timestampadd(Month,1,v_StartDateIn);
END IF;
declare v_StartDate datetime(3) default date_format(v_StartDateIn,126);
declare v_EndDate datetime(3) default date_format(v_EndDateIn,126);
declare v_Limit varchar(20) default 'Limit';
SELECT
concat(left(date_format(sl.StartStateDate,120),4)
,' ',
left(date_format(sl.StartStateDate,107),3)
,' ',
substring(date_format(sl.StartStateDate,120),9,2)) as Date
,Left(format(sl.StartStateDate,'D'),3) as Day
,substring(date_format(sl.StartStateDate,120),12,5) as Start
,substring(date_format(sl.EndStateDate,120),12,5) as End
FROM DataLogs sl
WHERE 1=1
and sl.StartStateDate >= v_StartDate
and sl.EndStateDate < v_EndDate
有人可以幫助我如何在MySQL中使用上述查詢。
導致錯誤?什麼錯誤? –