28.03.2024
Эффективная Навигация М2М
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум (скрипты, вопросы...) » Flagman (SpaceTeam) » Flagman » Скрипт проверки тарировки на ошибки
Скрипт проверки тарировки на ошибки
logoffДата: Пятница, 16.02.2018, 13:05 | Сообщение # 1
Тамбов
Группа: Администраторы
Сообщений: 655
Репутация: 19
Статус: Offline
Скрипт ищет разрывы или пересечения в тарировках в показаниях от датчиков
На выходе таблица с номера терминалов, номер датчика, его код в таблице

Цитата
declare @SensorId int,@SensorMin numeric (19,4), @SensorMax numeric (19,4),@LSensorMin numeric (19,4), @LSensorMax numeric (19,4)
/****** Скрипт для команды SelectTopNRows из среды SSMS  ******/
--SELECT TOP 1000 t.*
--  FROM [CP_ST-BusinessEntity].[Data]. [Taring]as t
-- left join [CP_ST-BusinessEntity].[Entity]. [Entity]as E on t.EntityId=e.EntityId
-- where t. [SensorId]= 4802 and e.Deleted is null
--order by SensorMin

declare @t table ( [SensorId]int,SensorMin float)

declare cur cursor local for
select distinct [SensorId]from [CP_ST-BusinessEntity].[Data]. [Taring]as T
left join [CP_ST-BusinessEntity].[Entity]. [Entity]as E2 on t.[SensorId]=e2.EntityId 
where e2.Deleted is null
-- and t.SensorId=6232

open cur
while 1=1 begin
FETCH NEXT FROM cur
INTO @SensorId
if @@FETCH_STATUS<>0  break

declare curTar cursor local for
select SensorMin, SensorMax from [CP_ST-BusinessEntity].[Data]. [Taring]as t
left join [CP_ST-BusinessEntity].[Entity]. [Entity]as E on t.EntityId=e.EntityId where t. [SensorId]= @SensorId and e.Deleted is null
order by SensorMin

--select @SensorId, t.SensorMin, t.SensorMax, t.*, e2.* from [CP_ST-BusinessEntity].[Data]. [Taring]as t
--left join [CP_ST-BusinessEntity].[Entity]. [Entity]as E on t.EntityId=e.EntityId 
--left join [CP_ST-BusinessEntity].[Entity]. [Entity]as E2 on t.[SensorId]=e2.EntityId 
--where t. [SensorId]= @SensorId and e.Deleted is null
--order by t.SensorMin

open curTar
FETCH NEXT FROM curTar
INTO @LSensorMin,@LSensorMax

while 1=1 begin
FETCH NEXT FROM curTar
INTO @SensorMin,@SensorMax
if @@FETCH_STATUS<>0  break
if @LSensorMax<>@SensorMin 
begin
print @LSensorMax
print @SensorMin
print '----' 
insert into @t values (@SensorId,@SensorMin);
end
select @LSensorMin = @SensorMin,@LSensorMax = @SensorMax
end
close curTar
deallocate curTar
end

close cur
deallocate cur

select distinct t.code, s.number, temp.SensorMin from @t as Temp  inner join [CP_ST-BusinessEntity].[Data]. [Sensor]as S on s.EntityId=Temp.SensorId
  inner join [CP_ST-BusinessEntity].[Data]. [Terminal]as T on s.TerminalId=t.EntityId
  left join [CP_ST-BusinessEntity].[Entity]. [Entity]as E on t.EntityId=Temp.SensorId
  left join [CP_ST-BusinessEntity].[Entity]. [Entity]as E2 on t.EntityId=e2.EntityId

  where e.Deleted is null and e2.Deleted is null
 
Форум (скрипты, вопросы...) » Flagman (SpaceTeam) » Flagman » Скрипт проверки тарировки на ошибки
  • Страница 1 из 1
  • 1
Поиск:

LogOff © 2024
Сайт создан в системе uCoz Рейтинг GPS Клуба. GPS навигаторы. GPS мониториг. GPS трекеры. ГЛОНАСС