add(sql):添加记录蒸汽数据的存储过程,2024/11/26确定的作业版本
- 新增名为 Record_SteamPointData 的存储过程 - 该过程用于记录蒸汽消耗数据 - 从 ems_record_steam_instant 表中获取最新数据 - 计算蒸汽消耗量并插入到 ems_report_point_steam 表中master
parent
474bdce3f3
commit
257dba0af3
@ -0,0 +1,51 @@
|
||||
CREATE PROCEDURE [dbo].[Record_SteamPointData]
|
||||
AS
|
||||
declare @begin_time datetime
|
||||
declare @end_time datetime
|
||||
BEGIN
|
||||
set @begin_time = DATEADD(hh, -1, GETDATE());
|
||||
set @end_time = DATEADD(hh, -0, GETDATE());
|
||||
declare @dateinfo datetime;
|
||||
set @dateinfo = GETDATE();
|
||||
INSERT INTO ems_report_point_steam (monitor_code, expend,instrument_value,begin_time,end_time,record_time)
|
||||
SELECT
|
||||
t1.monitor_code AS monitor_code,
|
||||
CONVERT(DECIMAL(18, 2), ISNULL((t3.steam_flow - t4.instrument_value),0)) AS expend,
|
||||
ISNULL(t3.steam_flow,0) AS instrument_value,
|
||||
DATEADD(HH, -1, @dateinfo) AS begin_time,
|
||||
DATEADD(HH, 0, @dateinfo) AS end_time,
|
||||
CONVERT(VARCHAR(30), DATEADD(HH, -1, @dateinfo), 120) AS record_time
|
||||
FROM ems_base_monitor_info t1
|
||||
LEFT JOIN (
|
||||
SELECT T1.monitor_code, T1.steam_flow, T1.collect_time
|
||||
FROM ems_record_steam_instant T1
|
||||
INNER JOIN (
|
||||
SELECT monitor_code, MAX(collect_time) AS latest_collect_time
|
||||
FROM ems_record_steam_instant
|
||||
WHERE collect_time BETWEEN @begin_time AND @end_time
|
||||
GROUP BY monitor_code
|
||||
) T2
|
||||
ON T1.monitor_code = T2.monitor_code AND T1.collect_time = T2.latest_collect_time
|
||||
WHERE T1.collect_time BETWEEN @begin_time AND @end_time
|
||||
) t3 ON t1.monitor_code = t3.monitor_code
|
||||
|
||||
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT E1.monitor_code,E1.begin_time,E1.instrument_value
|
||||
FROM ems_report_point_steam E1
|
||||
JOIN (
|
||||
SELECT monitor_code, MAX(begin_time) AS begin_time
|
||||
FROM ems_report_point_steam
|
||||
GROUP BY monitor_code) E2
|
||||
on E1.begin_time = E2.begin_time AND E1.monitor_code = E2.monitor_code
|
||||
) t4 ON t1.monitor_code = t4.monitor_code;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
END;
|
||||
go
|
||||
|
Loading…
Reference in New Issue