Сведение SQL к той части, которая относится к этому вопросу: (Вы даже не используете ничего из PLANTINGSPACE_EVW)
SELECT RA.Priority
, WO.Priority
, RA.WorkOrderGlobalID as RAWOGLBID
, WO.GlobalID
FROM CFAdmin.RISKASSESSMENT_EVW as RA
INNER JOIN CFAdmin.WORKORDER_EVW AS WO ON WO.GlobalID = RA.WorkOrderGlobalID
AND WO.Priority <> RA.Priority
WHERE WO.CancelDate IS NULL
AND WO.Status <> 2
AND WO.CreatedDate > cast('7/1/2018' as date)
AND WO.Type NOT IN (17, 18, 44, 45, 3)
AND WO.WOEntity = 0
Вы должны получить все записи, где приоритеты неmatch.
Я не могу проверить без выборочных данных, но как насчет этого?
SELECT RA.Priority
, WO.Priority
, RA.InspectionGlobalID as RA_INSP_GLBID
, WO.InspectionGlobalID
, RA.WorkOrderGlobalID as RAWOGLBID
, WO.GlobalID
, WO.OBJECTID as WOID
, RA.OBJECTID RA_OBJECTID
FROM CFAdmin.RISKASSESSMENT_EVW as RA
INNER JOIN CFAdmin.WORKORDER_EVW AS WO ON WO.GlobalID = RA.WorkOrderGlobalID
WHERE WO.GlobalId not in (
SELECT distinct WO2.GlobalID
FROM CFAdmin.RISKASSESSMENT_EVW as RA2
INNER JOIN CFAdmin.WORKORDER_EVW AS WO2 ON WO2.GlobalID = RA2.WorkOrderGlobalID
AND WO2.Priority = RA2.Priority
)
AND WO.CancelDate IS NULL
AND WO.Status <> 2
AND (WO.CreatedDate > '7/1/2018')
AND WO.Type NOT IN (17, 18, 44, 45, 3)
AND WO.WOEntity = 0