首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

将 expression 转换为数据类型 datetime 时出现算术溢出异常

2012-02-29 
将 expression 转换为数据类型 datetime 时出现算术溢出错误将 expression 转换为数据类型 datetime 时出

将 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 wheredatediff(mm, ltrim(a.YEAR)+'-'+ltrim(cast(a.PERIOD as int))+'-'+'01', getdate()) between 1 and 12and isdate(ltrim(a.YEAR)+'-'+ltrim(cast(a.PERIOD as int))+'-'+'01')=1 

热点排行
Bad Request.