日期:2014-05-18  浏览次数:21695 次

将 expression 转换为数据类型 datetime 时出现算术溢出错误
将 expression 转换为数据类型 datetime 时出现算术溢出错误
select * from AP_OESHDT_SALES_HIST_DETAILS a where
datediff(mm, ltrim(a.YEAR)+'-'+ltrim(a.PERIOD)+'-'+'01', getdate()) between 1 and 12
year 和period都是decmial(5,0),为什么会抱这个错那错
这条语句主要查当前日期之前12个月的数据

------解决方案--------------------
SQL code
select * 
from AP_OESHDT_SALES_HIST_DETAILS a 
where
datediff(mm, ltrim(a.YEAR)+'-'+ltrim(cast(a.PERIOD as int))+'-'+'01', getdate()) between 1 and 12
and isdate(ltrim(a.YEAR)+'-'+ltrim(cast(a.PERIOD as int))+'-'+'01')=1