有一张表:
房间    到达时间   中午或晚上
202     13:30
203     17:50
205     20:10
我现在要用SQL自动生成一列,即让点菜时间 晚于16:00的都记录为“晚上”,否则记录为“中午” ,用SQL是否可以实现,如果能实现,请指点 ,谢谢 !

解决方案 »

  1.   

    select 房间,到达时间,case when datediff(min,到达时间,'16:00')>0 then '晚上' else '中午' end as 中午或晚上
    202     13:30
    203     17:50
    205     20:10
      

  2.   

    select 房间,到达时间,case when datediff(min,到达时间,'16:00')>0 then '晚上' else '中午' end as 中午或晚上 from table1
      

  3.   

    写错一个,更正如下:
    select 房间,到达时间,case when datediff(minute,到达时间,'16:00')>0 then '晚上' else '中午' end as 中午或晚上 from table1
      

  4.   

    create table #(房间 varchar(10),   到达时间 varchar(10),  中午或晚上 varchar(10))
    insert into #(房间,到达时间) select '202',     '13:30'
    union all select '203',     '17:50'
    union all select '205',     '20:10'
    update # set 中午或晚上 = case when cast(left(到达时间,2)as int)>16 then '晚上' else '中午' endselect * from #
    --如果是字符类型.....