sql
No notes
Syntax:
SQL
SELECT dStartTime, Device.nDeviceID, MonitorState.nInternalMonitorState, ISNULL(dEndTime, GETDATE()) AS dEndTime, MonitorState.nMonitorStateID FROM ActiveMonitorStateChangeLog INNER JOIN MonitorState ON MonitorState.nMonitorStateID = ActiveMonitorStateChangeLog.nMonitorStateID INNER JOIN PivotActiveMonitorTypeToDevice ON PivotActiveMonitorTypeToDevice.nPivotActiveMonitorTypeToDeviceID = ActiveMonitorStateChangeLog.nPivotActiveMonitorTypeToDeviceID INNER JOIN Device ON Device.nDeviceID = PivotActiveMonitorTypeToDevice.nDeviceID INNER JOIN ActiveMonitorType ON ActiveMonitorType.nActiveMonitorTypeID = PivotActiveMonitorTypeToDevice.nActiveMonitorTypeID WHERE PivotActiveMonitorTypeToDevice.nPivotActiveMonitorTypeToDeviceID = 3499 AND ((dStartTime >= '2009-05-18' AND ISNULL(dEndTime, GETDATE()) <= '2010-04-22') OR (dStartTime <= '2010-04-22' AND ISNULL(dEndTime, GETDATE()) >= '2009-05-18') OR (dStartTime <= '2010-04-22' AND ISNULL(dEndTime, GETDATE()) >= '2010-04-22') OR (dStartTime <= '2009-05-18' AND ISNULL(dEndTime, GETDATE()) >= '2010-04-22') ) ORDER BY dStartTime ASC;