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

数据库表有begintime endtime两个时间类型字段,取现在任一时间,查询数据库记录有关问题?

2012-01-09 
数据库表有begintime endtime两个时间类型字段,取现在任一时间,查询数据库记录问题??数据库表T_timemark b

数据库表有begintime endtime两个时间类型字段,取现在任一时间,查询数据库记录问题??
数据库表T_time
mark begintime endtime
0 8:00:00 16:00:00
1 16:00:00 0:00:00
2 0:00:00 8:00:00

比如我现在已知电脑时间为 9:00:00如何查出第一条记录?比如已知时间为17:00:00,如何查出第二条记录??
select * from t_time where begintime<='9:00:00' and endtime>'9:00:00'
或 select * from t_time '9:00:00' between begintime and endtime 都不可以呀,怎么整??

[解决办法]
假设begintime,endtime为字符型
select * from tb where convert(varchar(8),getdate(),114) >= begintime and convert(varchar(8),getdate(),114) <= endtime
[解决办法]
俺都2005,也用过2000,没见过可视化之后把datetime的日期部分给不可视了:

SQL code
SELECT *FROM t_time WHERE (convert(varchar,GETDATE(),114) > convert(varchar,BEGINTIME,114) AND (convert(varchar,GETDATE(),114) < convert(varchar,ENDTIME,114))--行SELECT *FROM t_time WHERE (convert(varchar,'9:00:00',114) > convert(varchar,BEGINTIME,114) AND (convert(varchar,'9:00:00',114) < convert(varchar,ENDTIME,114))--也行 

热点排行
Bad Request.