将MS SQL查询转换为MySQL时出错

时间:2014-01-30 05:23:42

标签: mysql sql

我在C#中有一个项目,我必须在我的数据访问层文件中将MS SQL查询转换为MySQL查询。转换后我遇到“在命令执行期间遇到致命错误”。错误。以下是我的MySQL查询

SELECT * 
FROM   mst_tariff 
WHERE  service_id = @service_id     
AND ( effective_from BETWEEN STR_TO_DATE(@EFFECTIVE_FROM,'%d/%m/%Y %H:%i:%s') 
AND STR_TO_DATE(@EFFECTIVE_TO,'%d/%m/%Y %H:%i:%s')              
OR effective_to BETWEEN STR_TO_DATE(@EFFECTIVE_FROM,'%d/%m/%Y %H:%i:%s') 
AND STR_TO_DATE(@EFFECTIVE_TO,'%d/%m/%Y %H:%i:%s')      
OR STR_TO_DATE(@EFFECTIVE_FROM,'%d/%m/%Y %H:%i:%s') BETWEEN effective_from AND  
effective_to )      
AND is_active = 'y'   
AND tariff_id != @tariff_id

以下是我的MS SQL查询

SELECT * 
FROM   mst_tariff 
WHERE  service_id = @service_id     
AND ( effective_from BETWEEN convert(datetime,@EFFECTIVE_FROM,103) AND convert  
(datetime,@EFFECTIVE_TO,103)              
OR effective_to BETWEEN convert(datetime,@EFFECTIVE_FROM,103) AND convert  
(datetime,@EFFECTIVE_TO,103)      
OR convert(datetime,@EFFECTIVE_FROM,103) BETWEEN convert(datetime,effective_from,103) AND convert
(datetime,effective_to,103) )      
AND is_active = 'y'   
AND tariff_id != @tariff_id

此处,effective_from和effective_to是日期列。

我对此很新。所以任何人都可以验证查询是否是rite,是否从MS Sql到MySQL的转换是正确的。 提前致谢

0 个答案:

没有答案