My code:
我的代码:
DECLARE report_date DATETIME;
set report_date='2013-01-17 00:00:00';
SELECT *
FROM `NMPP`.`capacitypersecond`
WHERE `StreamDT` >=report_date and `StreamDT` < '2013-01-18 00:00:00' ;
SELECT *
FROM `NMPP`.`capacityperHr`
WHERE `StreamDT` >=report_date and `StreamDT` < '2013-01-18 00:00:00' ;
SELECT *
FROM `NMPP`.`capacityperDay`
WHERE `TJLDate` >=report_date and `TJLDate` < '2013-01-18 00:00:00' ;
-
- - - - - -
DECLARE report_date DATETIME;
/* SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE report_date DATETIME' at line 1 */
/* Affected rows: 0 Found rows: 0 Warnings: 0 Duration for 0 of 5 queries: 0.000 sec. */
3 个解决方案
#1
7
get rid of declare
:
摆脱声明:
set @report_date = '2013-01-17 00:00:00';
SELECT *
FROM `NMPP`.`capacitypersecond`
WHERE `StreamDT` >= @report_date and `StreamDT` < '2013-01-18 00:00:00' ;
#2
10
or with cast:
或与演员:
set @report_date = cast('2013-01-17 00:00:00' as datetime);
#3
-1
All the DECLARE should be at the start of the trigger,stored procedure.
所有的声明应该在触发器的开始,存储过程。
This is not a C++ like language where you can mix declarations and statements, but more like C, where all declarations must be done before all statements.
这不是一个c++语言,您可以将声明和语句混合在一起,但更像C,在所有语句之前都必须执行所有声明。
#1
7
get rid of declare
:
摆脱声明:
set @report_date = '2013-01-17 00:00:00';
SELECT *
FROM `NMPP`.`capacitypersecond`
WHERE `StreamDT` >= @report_date and `StreamDT` < '2013-01-18 00:00:00' ;
#2
10
or with cast:
或与演员:
set @report_date = cast('2013-01-17 00:00:00' as datetime);
#3
-1
All the DECLARE should be at the start of the trigger,stored procedure.
所有的声明应该在触发器的开始,存储过程。
This is not a C++ like language where you can mix declarations and statements, but more like C, where all declarations must be done before all statements.
这不是一个c++语言,您可以将声明和语句混合在一起,但更像C,在所有语句之前都必须执行所有声明。