SELECT Evnt_GUID,Transactiontimestamp,* from TestTrasncstion (NOLOCK), ( SELECT star.GlobalID Evnt_GUID, star.TimeGenerated StartTime, sto.TimeGenerated StopTime from (SELECT GlobalID, SpecialEventName_s, TimeGenerated from JobsEvents (NOLOCK) where SpecialEventName_s='Job Stopped' and SpecialEventDescription_s like '%GUID%' ) sto, (SELECT GlobalID, SpecialEventName_s, TimeGenerated from JobsEvents (NOLOCK) where SpecialEventName_s='Job Started' and SpecialEventDescription_s like '%GUID%' ) star WHERE sto.GlobalID=star.GlobalID ) tab WHERE Transactiontimestamp BETWEEN tab.StartTime and tab.StopTime ORDER BY 2
join
SELECT tt.Evnt_GUID, tt.Transactiontimestamp, je.* FROM TestTrasncstion tt(NOLOCK) LEFT JOIN ( SELECT Evnt_GUID , StartTime = MIN(CASE WHEN SpecialEventName_s='Job Started' THEN TimeGenerated ELSE NULL END) , StopTime = MAX(CASE WHEN SpecialEventName_s='Job Stopped' THEN TimeGenerated ELSE NULL END) FROM JobsEvents GROUP BY Evnt_GUID WHERE SpecialEventDescription_s like '%GUID%' ) je (NOLOCK) ON tt.Evnt_GUID = je.Evnt_GUID AND tt.Transactiontimestamp BETWEEN je.StartTime and je.StopTime ORDER BY 2
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)