Querying Category Selection

Categories are tied to the reason tree and are not stored directly within the Timed_Event_Details table. To retrieve the categories associated with a particular downtime record or filter downtime by a particular category, the query must check the reason tree structure in the Event_Reason_Category_Data table.


SELECT	Start_Time, 
        End_Time, 
        ERC_Desc
FROM Timed_Event_Details ted
     LEFT JOIN Event_Reason_Category_Data ercd ON ted.Event_Reason_Tree_Data_Id =
                                               ercd.Event_Reason_Tree_Data_Id 
     LEFT JOIN Event_Reason_Catagories erc ON ercd.ERC_Id = erc.ERC_Id
WHERE	      PU_Id = @PUId
              AND Start_Time < @ReportEndTime 
              AND (	End_Time > @ReportStartTime
                        OR End_Time IS NULL)