慕村9548890
2022-12-15 17:13:15
create function [dbo].[dhp](@stcd varchar(10),@d1 varchar(100) )-- stcd 表示站點(diǎn)編號 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貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超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 關(guān)注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消