標籤:資料 sp c ef r 演算法 bs sql as
在採集電錶資料的時候,可以發現有些電錶裝置讀數會發生復原。這時候,如果單純的累加計算用電量,就會出現負值。當然,這也許和電錶的品質有關係。
“RTQty”(當前讀到的讀數)、“LastQty”(上次讀數)、“PrecedingQty”(前次讀數)、”ErrorFlag”(錯誤標示)、”IncreaseQty”(增量讀數)、“IncreaseQtyOlder”(前次增量讀數)。
--判斷錯誤發生標示位
if @ErrorFlag=0
begin
--錯誤標示位為0,那麼計算本次的增量值
set @[email protected] RTQty [email protected] LastQty;
end
else
begin
--錯誤標示位為1,
--計算當前值和上次值的增量@IncreaseQty,
--計算當前值和前次值的增量[email protected]
set @IncreaseQty= RTQty - LastQty;
set @IncreaseQtyOlder= RTQty [email protected];
if @IncreaseQtyOlder>=0
begin
set @[email protected]
end
end
if @IncreaseQty>=0 ---如果增量不為負數
begin
--更新指定裝置的資料點位,上次數值為當前值,更新前次數值為當前值,設定錯誤標示為0。
update Meter set LastQty [email protected], PrecedingQty [email protected] RTQty,ErrorFlag=0 where [email protected]
--進行資料的其它計算
end
else
begin
--更新指定裝置的資料點位,上次數值為當前值,設定錯誤標示為1。
update Meter set LastQty [email protected],ErrorFlag=1 where [email protected]
--錯誤資訊插入到警報表
end
電錶讀數歸零復原SQL處理演算法