Downtime Events

Order Field Name Values/Table Reference
0 Result Set Type 5
1 Unit Id
  • Timed_Event_Details.PU_Id
  • Prod_Units.PU_Id
2 Location Id
  • Timed_Event_Details.Source_PU_Id
  • Prod_Units.PU_Id
3 Status Id
  • Timed_Event_Details.TEStatus_Id
  • Timed_Event_Status.TEStatus_Id
4 Fault Id
  • Timed_Event_Details.TEFault_Id
  • Timed_Event_Faults.TEFault_Id
5 Reason 1 Id
  • Timed_Event_Details.Reason_Level1
  • Event_Reasons.Reason_Id
6 Reason 2 Id
  • Timed_Event_Details.Reason_Level2
  • Event_Reasons.Reason_Id
7 Reason 3 Id
  • Timed_Event_Details.Reason_Level3
  • Event_Reasons.Reason_Id
8 Reason 4 Id
  • Timed_Event_Details.Reason_Level4
  • Event_Reasons.Reason_Id
9 Production Rate Timed_Event_Details.Production_Rate
10 Duration Timed_Event_Details.Duration
11 Transaction Type
  • 1 = Add
  • 2 = Update
  • 3 = Delete
  • 4 = Close
12 Start Time Timed_Event_Details.Start_Time
13 End time Timed_Event_Details.End_Time
14 Downtime Event Id Timed_Event_Details.TEDet_Id

The Downtime result sets do not have a post-update option so you should not attempt to manually insert records and then issue a result set. If you do, you risk undoing changes that you have already made. For example, if you open an event and issue the result set and then close the event a second later before the DBMgr has had a chance to process the result set, the DBMgr will end up reopening the event when it does get around to processing the result set.

Example


DECLARE	@MachineDown     int,
	       @PUId	     int,
	       @LocationId     int,
	       @ReasonId1      int,
	       @StartTime      datetime

DECLARE @DowntimeEvents TABLE (
ResultSetType	int DEFAULT 5,
PUId	         int NULL,
SourcePUId	   int NULL,
StatusId	     int NULL,
FaultId	      int NULL,
ReasonLevel1	 int NULL,
ReasonLevel2	 int NULL,
ReasonLevel3	 int NULL,
ReasonLevel4	 int NULL,
ProdRate	     int NULL,
Duration	     float NULL,
TransType	    int Default 1,
StartTime	    varchar(50) NULL,
EndTime	      varchar(50) NULL,
TEDetId	      int NULL)
SELECT @PUId = PU_Id
FROM Prod_Units
WHERE PU_Desc = 'MyUnit'

SELECT @LocationId = PU_Id 
FROM Prod_Units
WHERE PU_Desc = 'MyLocation'

SELECT @ReasonId1 = Event_Reason_Id 
FROM Event_Reasons
WHERE Event_Reason_Name = 'MyReason'

IF @MachineDown = 1 BEGIN
-- The following opens the downtime event 
INSERT INTO @DowntimeEvents (	PUId,
                                   SourcePUId, 
                                   ReasonLevel1, 
                                   StartTime)
VALUES (@PUId,
        @LocationId, 
        @ReasonId1,
         convert(varchar(50), getdate(), 120))
END
ELSE
BEGIN
-- Get the current downtime event 
 SELECT @StartTime = Start_Time 
 FROM Timed_Event_Details 
 WHERE PU_Id = @PUId
 AND Start_Time <= getdate() 
 AND End_Time IS NULL

-- The following closes the downtime event
INSERT INTO @DowntimeEvents (   TransType,
                                PUId,
                                StartTime, 
                                EndTime)
 
VALUES (	4,
              @PUId, 
              @StartTime,
              convert(varchar(50), getdate(), 120))
END

-- Output results
SELECT	     ResultSetType, 
                 PUId,
                 SourcePUId, 
                 StatusId, 
                 FaultId, 
                 ReasonLevel, 
                 ReasonLeve2, 
                 ReasonLeve3, 
                 ReasonLeve4, 
                 ProdRate, 
                 Duration , 
                 TransType, 
                 StartTime, 
                 EndTime,
                 TEDetId 
FROM @DowntimeEvents