declare @t table(Field datetime,Value int)
insert into @t select '2006-01-03',5
union all select '2005-12-26',3
union all select '2005-12-23',7
union all select '2005-12-22',22
union all select '2005-12-28',2
select top 1 field,value,[abs]=abs(datediff(dd,'2005-12-25',field))
from @t 
where field=(select max(field) from @t where field<'2005-12-25') 
or field=(select min(field) from @t where field>'2005-12-25')
order by abs(datediff(dd,'2005-12-25',field))

解决方案 »

  1.   

    --生成测试数据
    Create table #1 (field datetime,value numeric(9,1))
    insert into #1
    select   '2005-12-03' ,    6
    union all select
      '2005-12-03'    ,  4.5
    union all select
      '2005-12-19'    ,  7
    union all select
      '2005-12-28'    ,  6
    union all select
      '2006-01-03'    ,  3
    union all select
      '2005-12-13'    , 9declare @Date datetime --需要日期
    set @date='2005-12-18'if exists(select 1 from #1 where field=@date)
    select top 1 value from #1 where field=@date
    else
    select top 1 value from #1 where field=(select max(field) from #1 where field<@date)--删除测试表
    drop table #1