什么错误? "将 expression 转换为数据类型 datetime 时发生算术溢出错误"

asp2001 2005-04-02 10:55:33
程序昨天还运行得好好的 今天早上一运行 出现:
"将 expression 转换为数据类型 datetime 时发生算术溢出错误"

查询语句如下:
select count(*) from tblA where DATEPART(yy,Dateinput)='2005'
其中Dateinput是文本格式 如2005-04-02

但这段程序昨天还运行正常,期间服务器也没有重新启动过,就变成这样了.





...全文
1536 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
asp2001 2005-04-02
  • 打赏
  • 举报
回复
To zjcxc(邹建)
select Dateinput,* from tblA where isdate(Dateinput)=0

恩 是这个原因 有会员输入的日期格式错误引起的


asp2001 2005-04-02
  • 打赏
  • 举报
回复
select count(*) from tblA where DATEPART(yy,replace(Dateinput,' ',''))='2005'
也是不能运行的
zjcxc 元老 2005-04-02
  • 打赏
  • 举报
回复
--用下面的语句可以查询出表中异常的数据

select Dateinput,* from tblA where isdate(Dateinput)=0
zjcxc 元老 2005-04-02
  • 打赏
  • 举报
回复
select count(*) from tblA where DATEPART(yy,'2005-04-02')='2005'
可以运行


那说明还是你表中数据的问题
heyixiang 2005-04-02
  • 打赏
  • 举报
回复
这个问题要收藏
xluzhong 2005-04-02
  • 打赏
  • 举报
回复
select count(*) from tblA where DATEPART(yy,replace(Dateinput,' ',''))='2005'
xluzhong 2005-04-02
  • 打赏
  • 举报
回复
if datepart(yy,'2005-04-02 ')='2005'
begin
select 'a'
end
select 'b'
asp2001 2005-04-02
  • 打赏
  • 举报
回复
select count(*) from tblA where DATEPART(yy,'2005-04-02')='2005'
可以运行
zjcxc 元老 2005-04-02
  • 打赏
  • 举报
回复
查询分析器执行下面的语句会否出错?:

select datepart(yy,'2005-04-02 ')

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧