数据结构是这样的。
   time                 date
2006-05-01 12:00:00    1200
2006-05-01 13:00:00    3000
2006-05-01 14:00:00    1200
2006-05-02 12:00:00    3600
2006-05-02 13:00:00    3000
我想选出时间为2006-05-01的所有记录怎么写呀。

解决方案 »

  1.   

    declare @t table([time] datetime,[date] int)
    insert into @t select '2006-05-01 12:00:00'    ,1200
    union all select '2006-05-01 13:00:00'    ,3000
    union all select '2006-05-01 14:00:00'    ,1200
    union all select '2006-05-02 12:00:00'    ,3600
    union all select '2006-05-02 13:00:00'    ,3000select * from @t where [time]>='2006-05-01' and [time]<'2006-05-02'select * from @t where convert(varchar(10),[time],120)='2006-05-01'
      

  2.   

    select * from tablename where convert(varchar(10),[time],120)='2006-05-01'
      

  3.   

    select tm from tb where year(tm)=2005 and month(tm)=5 and day(tm)=1