--DPF5
USE dcf_date_test
SET NOCOUNT ON
GO
DECLARE @hh int
SET @hh = 8
while @hh<17begin
select @hh as hour,field,sum(add_sl) as sumadd,max(sl)-min(sl) as decc from dbo.temp_table
where rq between '2010-11-16 '+ cast(@hh as char(2))+':00:00' and '2010-11-16 '+cast(@hh+1 as char(2))+':00:00'and field
like 'zh2_all_ok_4%'group by field having sum(add_sl) is not null
order by field ascset @hh=@hh+1end
--================================
日期相减用datediff函数
sql="select * from table where datediff('d',enddate,date)<30"
浙公网安备 33010602011771号