海盗旗

曾经,蔚蓝的大海是冒险家们的乐园,海盗旗是他们在茫茫大海上的信仰和寄托

导航

循环函数

Posted on 2010-11-22 08:33  海盗旗  阅读(174)  评论(0)    收藏  举报

--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"