我想查询一辆车在一个月内的记录。于是编写了如下代码:
select * from 北京车辆能耗数据.dbo.北京朝批商贸股份有限公司
where
(
[列 0] in ('京AC3537')
and CAST ([列 2] as datetime)>'2013/11/1 00:00:00'
and CAST ([列 2] as datetime)<'2013/12/1 00:00:00'
)
order by CAST ([列 2] as datetime) asc
上述程序执行起来是没问题的。
后来,我想一次性查询两辆车在一个月内的记录。
于是代码更改为:
select * from 北京车辆能耗数据.dbo.北京朝批商贸股份有限公司
where
(
[列 0] in ('京AC3537','京AC3563')
and CAST ([列 2] as datetime)>'2013/11/1 00:00:00'
and CAST ([列 2] as datetime)<'2013/12/1 00:00:00'
)
order by CAST ([列 2] as datetime) asc
这时就出问题了,错误提示:从字符串转换日期和/或时间时,转换失败。
请教各位,问题出在了哪里?