Select top 1 * from tableName order by datediff(second,时间字段,给定时间)

解决方案 »

  1.   

    create table ab(i smalldatetime)
    insert into ab select '20031001'
    insert into ab select '20031002'
    insert into ab select '20031003'
    insert into ab select '20031101'
    insert into ab select '20031102'
    insert into ab select '20031103'select i,datediff(s,i,getdate()) n into #tem from abselect i from #tem 
    where abs(n) in(
    select min(abs(n)) from #tem)drop table #tem
    i                                                      
    ------------------------------------------------------ 
    2003-11-01 00:00:00(所影响的行数为 1 行)