SELECT ME MACHINE_EVENT_ID ME EVENT_TIME ME IS_BASIC ME STATE VIBRO_CH

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
SELECT
ME.MACHINE_EVENT_ID, ME.EVENT_TIME, ME.IS_BASIC, ME.STATE,
@VIBRO_CHANNELS AS VIBRO_CHANNELS,
@TACHO_CHANNELS AS TACHO_CHANNELS,
@REGIME_PARAMETERS AS REGIME_PARAMETERS,
(
select count(*) from tmeasurements m
where m.machine_event_id = me.machine_event_id
and exists
(
select tt.point_id from #TEMPTABLE_VIBRO_CHANNELS tt
where tt.point_id = m.point_id and tt.CHANNEL_SETTING_ID = m.CHANNEL_SETTING_ID and tt.PARAMETER_SETTING_ID = m.PARAMETER_SETTING_ID
)
) as cnt1
FROM
TMACHINE_EVENTS ME
WHERE ME.MACHINE_ID = @MACHINE_ID