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条件,一点点的缩小范围或者写一个正则来检查插入错的数据
------解决方案--------------------
改为这样
select * from catering
where [time] >= '2012-12-01' and [time]<'2013-01-01'