现有一个表table_12
表结构:
——————————————————————————————————————————
字段名 类型
id int(自增)
name nvarchar(50)
b_time datetime
e_time datetime
————————————————————————————————————————————记录:
——————————————————————————————————————————————————
id name b_time e_time
1 n_n1 9:30:00 12:30:00
2 n_n2 9:30:00 20:40:00
... ... ... ...
sql检索条件要满足以本地机时间为准,并在b_time和e_time范围内就让记录显出来,也就b_time<=now()<=e_time虽数定数据库的程序也写得很多了,但唯独这种情况是第一次遇到。特在此请教了。sqlp="select ID, p_name, P_Price, P_kwei, B_time, E_time from kc_products where c_id="&rskc("id")&" and getdate() between convert(char(11),getdate(),120)+b_time and convert(char(11),getdate(),120)+e_time"这样竟然一条记录也读不出来,程序也不报错.打印出来的SQL语句是这样的:select ID, p_name, P_Price, P_kwei, B_time, E_time from kc_products where c_id=16 and getdate() between convert(char(11),getdate(),120)+b_time and convert(char(11),getdate(),120)+e_time getdate() 当前时间是:10:00:00,大于10点的记录有很多,就是读不出来
表结构:
——————————————————————————————————————————
字段名 类型
id int(自增)
name nvarchar(50)
b_time datetime
e_time datetime
————————————————————————————————————————————记录:
——————————————————————————————————————————————————
id name b_time e_time
1 n_n1 9:30:00 12:30:00
2 n_n2 9:30:00 20:40:00
... ... ... ...
sql检索条件要满足以本地机时间为准,并在b_time和e_time范围内就让记录显出来,也就b_time<=now()<=e_time虽数定数据库的程序也写得很多了,但唯独这种情况是第一次遇到。特在此请教了。sqlp="select ID, p_name, P_Price, P_kwei, B_time, E_time from kc_products where c_id="&rskc("id")&" and getdate() between convert(char(11),getdate(),120)+b_time and convert(char(11),getdate(),120)+e_time"这样竟然一条记录也读不出来,程序也不报错.打印出来的SQL语句是这样的:select ID, p_name, P_Price, P_kwei, B_time, E_time from kc_products where c_id=16 and getdate() between convert(char(11),getdate(),120)+b_time and convert(char(11),getdate(),120)+e_time getdate() 当前时间是:10:00:00,大于10点的记录有很多,就是读不出来
解决方案 »
- sql里 删除表名abc开头的所有表 怎么写
- 我知道很多朋友都在做MIS,也知道很多朋友正为报表和数据库导到EXCEL发愁.
- ******查询的小小问题*****
- [求助]有没有可以修改数据库中某个表的某字段的默认值,这样的SQL语句或者存储过程?
- 求助!关于提取吉祥号的语句
- 怎样用SQL语句在SAP里生产订单里 实现输入重复生产批次时报警提示
- 求一视图(在线等)
- ms sql server2005数据库备份
- (送分)SQL2005 日志,报警 内存不足给出 ,给出 SQL2005 内存管理机制
- 在线等待各位救命,救救小弟,是关于sql.add(insert into 语句.............
- 问一个SQL SERVER 的全局变量 @@microsoftversion
- 如何取我选定的时间的这个月的数据!
--10:27:40
用这个
--10
也就是说最后的空格被自动处理掉了,楼主如果还像用原来的方法那就手动添加空格+''+
select convert(varchar(11),getdate(),120)+'10:23:23'
--2006-08-30 10:23:23
不好意思,我的len()居然有rtrim()的功效.在不用len()的时候空格确实没有消失,..恩再想个变通的办法...
insert into test select 'a','10:13:23','10:53:23'
insert into test select 'a','7:23:23','11:23:23'
insert into test select 'a','5:23:23','8:23:23'
-----得到如下结果集
1 a 1900-01-01 10:13:23.000 1900-01-01 10:53:23.000
2 a 1900-01-01 07:23:23.000 1900-01-01 11:23:23.000
3 a 1900-01-01 05:23:23.000 1900-01-01 08:23:23.000
--
即数据库默认会填满datetime类型的年月日.所以你的处理要改一下,表示你想象中那种拼接.
--如下就可以了
select ID, name, B_time, E_time
from test
where getdate() between convert(char(11),getdate(),120)+convert(char(8),b_time,108)
and convert(char(11),getdate(),120)+convert(char(8),e_time,108)