create view f as select id,case when startTime<'20:00' then SampleCount else SampleCount*1.0/2 end as SampleCount,starttime from tb
select ID,startTime,[SampleCount] = case when convert(varchar(12),startTime,108) <'20:00:00' then SampleCount else SampleCount /2 end from tb这样?
select id , case when convert(varchar(8),startTime,114) >= '20:00:00' then SampleCount / 2 else SampleCount end, SampleCount from tb
太原律师---wori ,老想呀!
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
select id,case when convert(varchar(8),startTime,114) >= '20:00:00' then SampleCount / 2 else SampleCount end as SampleCount,starttime from tb
select
id,case when startTime<'20:00' then SampleCount else SampleCount*1.0/2 end as SampleCount,starttime
from
tb
from tb这样?
select id ,
case when convert(varchar(8),startTime,114) >= '20:00:00' then SampleCount / 2
else SampleCount
end,
SampleCount
from tb
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
else SampleCount end as SampleCount,starttime
from tb