关于SQL查询两值之间

来源:百度知道 编辑:UC知道 时间:2024/06/15 15:41:24
同上,
我想查出 生产于 2008-1-1到2008-10-30 的产品,写的语句是

select * from 表 where time between 2008-1-1 and 2008-10-30

为什么显示出来是空记录呢,表里有2条适合的记录
加上单引号提示的是数据格式错误,时间那个字段属性是“时间/日期”

select * from 表 where time between #2008-1-1# and #2008-10-30#
这样后再试试
或是
select * from 表 where time between #2008-1-1 and #2008-10-30
或是
where time >= 2008-1-1 and time <= 2008-10-30
我记不大清楚了,呵呵,

不知道您是什么数据库?
在SQL SERVER 中
select * from 表 where
time between '2008-1-1' and '2008-10-30'
是正确的.
再不行您就试一试下面的语句:
select * from 表 where [time] between convert(datetime,'2005-1-1',120) and convert(datetime,'2007-1-1',120)

加上单引号没有错误的!
你的时间表名称是time吗?错误就在这里,建议你把time改成别的名称的话就不会有错误了!因为time在sql里面是关键字,是不能做字段名的!!!
如下
select * from 表 where 字段名称 between ‘2008-1-1’ and ‘2008-10-30’

测试成功!
祝你好运!