在表中有个字段为datetime的类型,里面存储的时间是以:yy.mm.dd hh: m: s.ms格式存储的.现需要查询某一段时间内的信息,用了如下的查询:declare @beginTime as datetime
declare @endtime as datetimeselect *
from table
where createtime>@beginTime -1 and createtime<@endTime +1查询出来的信息将以每天的12:00为时间段来分离.也就是说,如果要查26号的,则查处了26号12点到27号12点时间段的信息,而不是26号0点到24点内的,请问该怎样修改该查询呢?

解决方案 »

  1.   

    up---------------------------------------------------------------------------------------------
    腰缠70元到月入近10万
    http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=453IT工程师 毕业4年我年薪涨到30万 
    http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=51126岁青年坐拥千万域名资产 从小玩家变成CEO 
    http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=515程序员的酸甜苦辣:告别Coding 
    http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=341从月薪3500到700万(一)
    http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=170网络草根月赚3000的十种方法
    http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=517如果我是女的 我肯定不会嫁给做网站的
    http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=512
      

  2.   

    declare @beginTime as datetime
    declare @endtime as datetimeselect *
    from table
    where createtime>=dateadd(day,-1,@beginTime) and createtime<dateadd(day,1,@endTime)
      

  3.   

    create table test
    (
    da datetime
    )
    insert test
    select '2006-08-26 09:30:23.000' union all
    select '2006-08-27 09:30:23.000' union all
    select '2006-08-26 13:30:23.000' union all
    select '2006-08-26 23:30:23.000'
    select * from testselect * from test
    where da > '2006-08-26 00:00:00.000' and da < '2006-08-27 00:00:00.000'
    da                                                     
    ------------------------------------------------------ 
    2006-08-26 09:30:23.000
    2006-08-26 13:30:23.000
    2006-08-26 23:30:23.000(所影响的行数为 3 行)
      

  4.   

    declare @beginTime as datetime
    declare @endtime as datetimeselect *
    from table
    where createtime between covert(char(8),@beginTime,112) and covert(char(8),@endtime ,112)
      

  5.   

    select *
    from table
    where createtime between convert(char(8),@beginTime,112) and convert(char(8),@endtime ,112)