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

字符串 转日期,该怎么处理

2013-01-11 
字符串 转日期select * from cateringwhere time betweenconvert(datetime,2012-12-1 00:00:00,120) and

字符串 转日期
select * from catering  
where time between  convert(datetime,'2012-12-1 00:00:00',120) and convert(datetime,'2012-12-31 23:59:00',120) 


结果是查询到了  但是查询的数据不全

消息提示:
消息 241,级别 16,状态 1,第 1 行
从字符串转换日期和/或时间时,转换失败。



[解决办法]
select * from catering  
where convert(datetime,time) between  '2012-12-1 00:00:00' and '2012-12-31 23:59:00'
[解决办法]

引用:
已经解决了,数据库存放格式有点错误.":" 中英文状态下

一般如果报这种错误就用select输出转换一下
select convert(datetime,time) from catering  
然后加where条件,一点点的缩小范围或者写一个正则来检查插入错的数据
[解决办法]
本帖最后由 roy_88 于 2013-01-03 10:41:08 编辑 改为这样


select * from catering  
where [time] >=  '2012-12-01' and [time]<'2013-01-01'

热点排行
Bad Request.