create function [dbo].[dhp](@stcd varchar(10),@d1 varchar(100) )-- stcd 表示站点编号 d1表示时间returns decimalasbegindeclare @dhp decimalif (datename(hour,@d1)>'8')select @dhp= sum(drp) from st_pptn_r where stcd=@stcd and tm between @d1 and convert(varchar(100),year(dateadd(day,1,@d1)))+'-'+convert(varchar(100),month(dateadd(day,1,@d1)))+'-'+convert(varchar(100),day(dateadd(day,1,@d1)))+' 8:00:00'elseselect @dhp= sum(drp) from st_pptn_r where stcd=@stcd and tm between convert(varchar(100),year(dateadd(day,-1,@d1)))+'-'+convert(varchar(100),month(dateadd(day,-1,@d1)))+'-'+convert(varchar(100),day(dateadd(day,-1,@d1)))+' 9:00:00' and @d1return @dhpend
1 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
select case when stcd='stcd' and tm between 'd1' and convert(varchar(100),year(dateadd(day,1,'d1')))
+'-'+convert(varchar(100),month(dateadd(day,1,'d1')))
+'-'+convert(varchar(100),day(dateadd(day,1,'d1')))
+' 8:00:00' then sum(drp) when stcd='stcd' and tm between convert(varchar(100),year(dateadd(day,-1,'d1')))
+'-'+convert(varchar(100),month(dateadd(day,-1,'d1')))
+'-'+convert(varchar(100),day(dateadd(day,-1,'d1')))
+' 9:00:00' and 'd1' then sum(drp) end drpsum from st_pptn_r你把'stcd'和'd1'换成具体值,试试看。
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报
0/150
提交
取消