提取数据库时间为最近的的记录集  时间格式:2008-12-12

解决方案 »

  1.   

    select * from tablename where date=Max(date)
      

  2.   

    select * from table where date='2008-12-12'
    可否详细说说
      

  3.   

    select convert( varchar(10),max(date),120) from 表
      

  4.   

    select convert( varchar(10),cast(max(order_date) as datetime),120) from order_m
      

  5.   

    select convert(varchar(10),max(时间字段),120) from tableName
      

  6.   

    假设表中日期字段为 lastdate  SELECT  *   FROM  tableName
     WHERE lastdate=(SELECT  CONVERT(varchar(20),max(lastdate),120 ) FROM  tableName   )
     
      

  7.   

    declare @mytime varchar(64)
    set @mytime='2008-12-12'declare @t table(id int,c1 datetime)insert into @t
    select '1','2008-12-13'
    union all
    select '2','2008-12-26'
    union all
    select '3','2008-11-12'
    union all
    select '4','2008-10-01'
    --取近三天内的记录
    select * from @t where abs(datediff(day,convert(varchar(10),c1,120),@mytime))<=3
      

  8.   


    create table test(id int,sql_time datetime)insert  test values(1,'2008-12-05')
    insert  test values(2,'2007-11-05')
    insert  test values(3,'2007-10-09')
    insert  test values(4,'2006-11-05')
    insert  test values(5,'2005-10-05')select * from test where sql_time=(select max(sql_time) from test) 如时间字段为CHAR,也一样可以
    select * from test where sql_time=(select max(sql_time) from test)