--SELECT FROM TMACHINES DECLARE MACHINE_ID UNIQUEIDENTIFIER DECLARE EL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--SELECT * FROM TMACHINES
DECLARE @MACHINE_ID UNIQUEIDENTIFIER
DECLARE @ELEMENTS_ID UNIQUEIDENTIFIER
DECLARE @POINT_ID UNIQUEIDENTIFIER
DECLARE @EVENT_ID UNIQUEIDENTIFIER
DECLARE @ALARMS_FIND INT
DECLARE @TYPE_EVENT_ID INT
SET @MACHINE_ID = 'A310DAF2-D1D2-44F5-81D3-B2307D8CB458'
SET @TYPE_EVENT_ID = 3
SELECT * FROM
(
--ПОДКЛЮЧАЕМ ТОЧКИ (С ИХ ПАРАМЕТРАМИ) МОДЕЛИ АГРЕГАТА
SELECT
POINT_MM_SL.POINT_ID AS POINT_ID, PARAMETER_SETTING.PARAMETER_SETTING_ID
FROM TMACHINES MACHINE
INNER JOIN TPOINT_MM_SETTINGS_LINKS POINT_MM_SL ON POINT_MM_SL.MACHINE_MODEL_SETTING_ID = MACHINE.MACHINE_MODEL_SETTING_ID
INNER JOIN TPOINT POINT ON POINT.POINT_ID = POINT_MM_SL.POINT_ID
INNER JOIN TPOINT_SETTINGS POINT_SETTING ON POINT_SETTING.POINT_SETTING_ID = POINT.POINT_SETTING_ID
INNER JOIN TCHANNEL_SETTINGS CHANNEL_SETTING ON CHANNEL_SETTING.POINT_SETTING_ID = POINT_SETTING.POINT_SETTING_ID
INNER JOIN TPARENT_CHANNEL_PARAMETER_LINKS PARENT_CHANNEL_PARAMETER_LINK ON PARENT_CHANNEL_PARAMETER_LINK.CHANNEL_SETTING_ID = CHANNEL_SETTING.CHANNEL_SETTING_ID
INNER JOIN TPARAMETER_SETTINGS PARAMETER_SETTING ON PARAMETER_SETTING.PARAMETER_SETTING_ID = PARAMETER_SETTING.PARAMETER_SETTING_ID
WHERE MACHINE.MACHINE_ID = @MACHINE_ID
UNION ALL
--ПОДКЛЮЧАЕМ ТОЧКИ (С ИХ ПАРАМЕТРАМИ) МОДЕЛЕЙ ЭЛЕМЕНТОВ
SELECT
POINT_ELEMENT_MM_LINK.POINT_ID AS POINT_ID, PARAMETER_SETTING.PARAMETER_SETTING_ID
FROM TMACHINES MACHINE
INNER JOIN TELEMENT_MODEL_IN_MM_SETTINGS ELEMENT_MODEL_IN_MM_S ON MACHINE.MACHINE_MODEL_SETTING_ID = ELEMENT_MODEL_IN_MM_S.MACHINE_MODEL_SETTING_ID
INNER JOIN TPOINT_ELEMENT_MM_LINKS POINT_ELEMENT_MM_LINK ON POINT_ELEMENT_MM_LINK.ELEMENT_MODEL_IN_MM_SETTING_ID = ELEMENT_MODEL_IN_MM_S.ELEMENT_MODEL_IN_MM_SETTING_ID
INNER JOIN TPOINT POINT ON POINT.POINT_ID = POINT_ELEMENT_MM_LINK.POINT_ID
INNER JOIN TPOINT_SETTINGS POINT_SETTING ON POINT_SETTING.POINT_SETTING_ID = POINT.POINT_SETTING_ID
INNER JOIN TCHANNEL_SETTINGS CHANNEL_SETTING ON CHANNEL_SETTING.POINT_SETTING_ID = POINT_SETTING.POINT_SETTING_ID
INNER JOIN TPARENT_CHANNEL_PARAMETER_LINKS PARENT_CHANNEL_PARAMETER_LINK ON PARENT_CHANNEL_PARAMETER_LINK.CHANNEL_SETTING_ID = CHANNEL_SETTING.CHANNEL_SETTING_ID
INNER JOIN TPARAMETER_SETTINGS PARAMETER_SETTING ON PARAMETER_SETTING.PARAMETER_SETTING_ID = PARAMETER_SETTING.PARAMETER_SETTING_ID
WHERE MACHINE.MACHINE_ID = @MACHINE_ID
UNION ALL
--ПОДКЛЮЧАЕМ ПАРМЕТРЫ С VALUETYPE = "УСТАВКА"
SELECT
'00000000-0000-0000-0000-000000000000' AS POINT_ID,PARAMETER_SETTING.PARAMETER_SETTING_ID AS ELEMENT_ID
FROM TMACHINES MACHINE
INNER JOIN TPARAMETER_MM_SETTINGS_LINKS PARAMETER_MM_SL ON PARAMETER_MM_SL.MACHINE_MODEL_SETTING_ID = MACHINE.MACHINE_MODEL_SETTING_ID
INNER JOIN TPARAMS_IN_MM_LINKS PARAMS_IN_MM_LINKS ON PARAMS_IN_MM_LINKS.SRC_PARAMETER_SETTING_ID = PARAMETER_MM_SL.PARAMETER_SETTING_ID
INNER JOIN TPARAMETER_SETTINGS PARAMETER_SETTING ON PARAMETER_SETTING.PARAMETER_SETTING_ID = PARAMS_IN_MM_LINKS.SRC_PARAMETER_SETTING_ID
WHERE
MACHINE.MACHINE_ID = @MACHINE_ID
AND PARAMETER_SETTING.VALUE_TYPE_ID = 11
) AS MACHINE_POINTS
--SELECT * FROM TPARENT_CHANNEL_PARAMETER_LINKS