----2012-01-16 10:12:48.803
----2012-01-16 07:59:52.653
----2012-01-16 07:17:59.897
----2012-01-16 07:12:06.987
----2012-01-16 07:09:09.347
----2012-01-16 07:05:08.190---我想取时间(2012-01-16 07:59:52.653)以前的数据时间
    时间  <=  convert(datetime,'2012-01-16 07:59:52.653',21) 
     ----取出来的时间,把(2012-01-16 10:12:48.803)也包括在内
---如何写

解决方案 »

  1.   


    declare @T table (col datetime)
    insert into @T
    select '2012-01-16 10:12:48.803' union all
    select '2012-01-16 07:59:52.653' union all
    select '2012-01-16 07:17:59.897' union all
    select '2012-01-16 07:12:06.987' union all
    select '2012-01-16 07:09:09.347' union all
    select '2012-01-16 07:05:08.190'select * from @T where col<='2012-01-16 07:59:52.653'
    /*
    col
    -----------------------
    2012-01-16 07:59:52.653
    2012-01-16 07:17:59.897
    2012-01-16 07:12:06.987
    2012-01-16 07:09:09.347
    2012-01-16 07:05:08.190
    */
      

  2.   


    我在数据库里面定义的是datetime 类型,但是,在报表中显示,并且传值的时候,报表会自动转换成varchar类型,所以,我必须,转换成时间datetime类型,
    但是,这样一来,对比后,把,不该出现的 时间,也出现在列
      

  3.   

    无论表中的列是varchar 还是datetime的
    declare @T table (col varchar(24))
    insert into @T
    select '2012-01-16 10:12:48.803' union all
    select '2012-01-16 07:59:52.653' union all
    select '2012-01-16 07:17:59.897' union all
    select '2012-01-16 07:12:06.987' union all
    select '2012-01-16 07:09:09.347' union all
    select '2012-01-16 07:05:08.190'select * from @T where col <=  convert(datetime,'2012-01-16 07:59:52.653',21) 
    /*
    ------------------------
    2012-01-16 07:59:52.653
    2012-01-16 07:17:59.897
    2012-01-16 07:12:06.987
    2012-01-16 07:09:09.347
    2012-01-16 07:05:08.190
    */declare @T1 table (col datetime)
    insert into @T1
    select '2012-01-16 10:12:48.803' union all
    select '2012-01-16 07:59:52.653' union all
    select '2012-01-16 07:17:59.897' union all
    select '2012-01-16 07:12:06.987' union all
    select '2012-01-16 07:09:09.347' union all
    select '2012-01-16 07:05:08.190'select * from @T1 where col <=  convert(datetime,'2012-01-16 07:59:52.653',21) 
    /*
    ------------------------
    2012-01-16 07:59:52.653
    2012-01-16 07:17:59.897
    2012-01-16 07:12:06.987
    2012-01-16 07:09:09.347
    2012-01-16 07:05:08.190
    */
    执行楼主所给出的语句没有发现楼主所诉的问题
      

  4.   


    --在比较的时候都转成时间就可以了declare @T1 table (col datetime)
    insert into @T1
    select '2012-01-16 10:12:48.803' union all
    select '2012-01-16 07:59:52.653' union all
    select '2012-01-16 07:17:59.897' union all
    select '2012-01-16 07:12:06.987' union all
    select '2012-01-16 07:09:09.347' union all
    select '2012-01-16 07:05:08.190'select * from @T1 where 
    cast (col as datetime) <=  
    cast ('2012-01-16 07:59:52.653' as datetime)
      

  5.   

    我早已经把时间,全部转换成时间,datetime  类型,比较,只能期待平台内部逻辑,处理,能否把时间,同时提交。
    谢谢
      

  6.   


    col <=  convert(datetime,'2012-01-16 07:59:52.653',21)转换一下,不会出现吧