现有一个表table_12
表结构:
——————————————————————————————————————————
字段名    类型
id                   int(自增)
name              nvarchar(50)
b_time            datetime
e_time            datetime
————————————————————————————————————————————记录:
——————————————————————————————————————————————————
id            name             b_time                   e_time
1             n_n1             10:30:00                12:30:00 
2             n_n2             18:30:00                20:40:00  
...              ...                  ...                          ...
sql检索条件要满足以本地机时间为准,并在b_time和e_time范围内就让记录显出来,也就b_time<=now()<=e_time虽数定数据库的程序也写得很多了,但唯独这种情况是第一次遇到。特在此请教了。

解决方案 »

  1.   

    本地时间?是指客户机的时间吧。好办,在客户端应用程序中取得本机时间,作为查询参数即可。select * from table_12 where 时间 between convert(char(8),b_time,108) and convert(char(8),e_time,108)
      

  2.   

    用服务器时间会统一点
    where getdate() between convert(char(11),getdate(),120)+b_time and convert(char(11),getdate(),120)+e_time
      

  3.   

    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"这样竟然一条记录也读不出来,程序也不报错.
      

  4.   

    b_time 和e_time
    在执行前显示sqlp看一下就清楚了
      

  5.   

    打印出来的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点的记录有很多,就是读不出来表:kc_products ---------------------------------------------------------------
    id            name             b_time                   e_time
    1             n_n1             9:00:00                12:30:00 
    2             n_n2             9:30:00                20:40:00
      

  6.   

    SELECT *  FROM table_12
    where 
    getdate() between
    convert(datetime,convert(char(11), getdate(), 120)+' ' + b_time) 
    and
    convert(datetime,convert(char(11), getdate(), 120)+' ' + e_time)