有一张原始表,包括了ID,SampleCount,startTime等列,现在想建一个视图,当startTime小于20:00时,正常获得SampleCount,当startTime大于20:00时,获取SampleCount的一半,这个视图如何写??求高人指点

解决方案 »

  1.   

    create view f as
    select 
     id,case when startTime<'20:00' then SampleCount else SampleCount*1.0/2 end as SampleCount,starttime
    from
     tb
      

  2.   

    select ID,startTime,[SampleCount] = case when convert(varchar(12),startTime,108) <'20:00:00' then SampleCount  else SampleCount /2 end 
    from tb这样?
      

  3.   


    select id , 
           case when convert(varchar(8),startTime,114) >= '20:00:00' then SampleCount / 2
                else SampleCount
           end,
           SampleCount
    from tb
      

  4.   

    太原律师---wori ,老想呀!
      

  5.   

    if object_id('tb') is not null
    drop table tb
    go
    create table tb
    (
    id int identity(1,1) primary key,
    SampleCount int,startTime datetime
    )
    insert into tb(SampleCount,startTime)
    select 56,'2009-8-1' union all
    select 56,'2009-9-1' union all
    select 56,'2009-7-1' union all
    select 56,'2009-6-1' union all
    select 56,'2009-10-1' union all
    select 56,'2009-2-1' select aa=(case when startTime>convert(datetime,'2009-8-1') then SampleCount else SampleCount/2  end) from tb
      

  6.   

    select id,case when convert(varchar(8),startTime,114) >= '20:00:00' then SampleCount / 2
    else SampleCount  end as SampleCount,starttime
    from tb