----是这个意思麽?
create table tab(time datetime,num int)
insert tab
select '20070801 01:01:000',1
union select '20070802 09:01:000',2
union select '20070803 10:01:000',3
union select '20070804 15:01:000',4
select num=sum(case when DATEPART(HH,time) between 8 and 20 then num else 0 end)
from tab
where convert(char(10),time,120) between '2007-08-01' and '2007-08-04'
select num=sum(case when DATEPART(HH,time) between 8 and 20 then num else 0 end)
from 表
where convert(char(10),time,120) between '2007-08-01' and '2007-08-04'
---?
select num=sum(case when hour(time) between 8 and 20 then num else 0 end)
from 表
where convert(char(10),time,120) between '2007-08-01' and '2007-08-04'