SQLServer The datediff function resulted in an overflow
来源:互联网 发布:匹诺曹软件下载 编辑:程序博客网 时间:2024/06/11 23:21
开发同事有一个脚本报错,很简单,简写如下:
SELECTCOUNT(*)FROMLogs t1 with(nolock)WHEREDATEDIFF(s, '2016-08-18 17:06:35', t1.insertTime) < 0
执行后出错!
Msg 535, Level 16, State 0, Line 1
The datediff function resulted in an overflow.
The number of dateparts separating two date/time instances is too large.
Try to use datediff with a less precise datepart.
datediff 函数计算溢出!难道 datediff 计算出来的的秒数超出了范围?
果然,官方文档如下:(DATEDIFF (Transact-SQL))
如果返回值超出 int 的范围(-2,147,483,648 到 +2,147,483,647),则会返回一个错误。 对于 millisecond,startdate 与enddate 之间的最大差值为 24 天 20 小时 31 分钟 23.647 秒。 对于 second,最大差值为 68 年。
查看数据库,竟然有7行时间为: 2099-08-10 11:33:37.367 ,这样转换肯定出错了,错误如上一样。可以试试。
select DATEDIFF(s, '2000-01-01 00:00:00', '2068-01-19 04:00:00')select DATEDIFF(s, '2000-01-01 00:00:00', '2068-01-19 03:00:00') --2147482800
相差秒数为 2147482800,为 整型 int 的范围内。
也可以看看 datediff 返回的类型是什么:整型
SELECT SQL_VARIANT_PROPERTY(DATEDIFF(s, '2000-01-01 00:00:00', '2068-01-19 03:00:00'),'BaseType')
所以,数据库存在了日期较大的值,这几行日期字段原本也是错误的数据,应该把日期改掉。还有就是语句写法也有问题,不应该这么写,应改成下面的写法更规范,否则即使有索引也不能使用!
SELECTCOUNT(*)FROMLogs t1 with(nolock)WHERE t1.insertTime < '2016-08-18 17:06:35'
0 0
- SQLServer The datediff function resulted in an overflow
- Error:Your step-into request resulted in an automatic step-over of a property or operator.
- In C++, what’s the difference between an inline function and a macro?
- SQLSERVER 中DATEDIFF函数
- sqlserver datediff格式转换
- [Javascript] A function works like 'print_r()' in PHP to print out the details of an object for JS debugging
- mysql sqlserver hibernate 有数据库关键字 You have an error in your SQL syntax; check the manual that corres
- the function modules called in the transaction
- sqlserver计算时间差DATEDIFF 函数
- SQLServer datediff () 函数 使用例子
- SqlServer中datediff、datename、datepart。。。
- stack overflow--recursive function
- Creating a Stored Procedure or Function in an Oracle Database
- Warning : caught an JavaWebDeveloperException() in MobiAppAge.foward() function
- MDK Executing a function or an interrupt handler in RAM
- iconv() [function.iconv]: detected an illegal character in input string
- The Lifetime of Variants Declared in Function
- Use the edge function in matlab
- DirectX3D游戏制作之---游戏界面的设计
- Android根据屏幕大小加载图片到内存
- Android UI(RatingBar)详解
- Android开发-获取当前系统时间-常用操作
- js定义map,jsp调用
- SQLServer The datediff function resulted in an overflow
- 平衡二叉树(AVL树)
- hdu5867 中位数
- viewpager画小圆点
- Centos6.7操作系统mysql-5.5cmake 源码编译安装
- 开通
- ffmpeg主要数据结构及其之间的关系
- [Codeforces 487E]Tourists/[JZOJ4691]旅行/[UOJ#30]Tourists
- Android Studio创建JNI项目(一)