我不知道下面的存储过程中存在什么问题:
CREATE PROCEDURE `GetDataByColNameByTime
`(
IN Col_Name VARCHAR(50),
IN DateStart VARCHAR(50), IN DateEnd VARCHAR(50) )
BEGIN
SET @sqlx =
CONCAT
('SELECT ', Col_Name , ' , SAMPLE_TIME FROM indicator_data_history I
WHERE ( I.SAMPLE_TIME >= `2014-04-04 11:47:57` )
AND ( I.SAMPLE_TIME <= `2014-04-04 11:33:57` )
order by SAMPLE_TIME');
PREPARE stmtx FROM @sqlx;
EXECUTE stmtx;
如果用简单的语句编写,我可以进行类似的查询:
SELECT RT , SAMPLE_TIME FROM indicator_data_history I WHERE ( I.SAMPLE_TIME >= '2014-04-04 11:47:57' ) AND ( I.SAMPLE_TIME <= '2014-04-04 11:33:57' ) ;
分析后,引号似乎是问题2014-04-04 11:33:57
- 任何想法如何解决这个问题?
答案 0 :(得分:1)
反引号(`)用于列名和表名。单引号(')用于字符串。例如,这是无效的:
I.SAMPLE_TIME >= `2014-04-04 11:47:57`
这是有效的:
I.SAMPLE_TIME >= '2014-04-04 11:47:57'