sql

by mattias on March 12th, 2010
No notes
Syntax: SQL
Show lines - Hide lines - Show in textbox - Download
  1. SELECT dStartTime, Device.nDeviceID, MonitorState.nInternalMonitorState, ISNULL(dEndTime, GETDATE()) AS dEndTime, MonitorState.nMonitorStateID
  2. FROM ActiveMonitorStateChangeLog
  3. INNER JOIN MonitorState ON MonitorState.nMonitorStateID = ActiveMonitorStateChangeLog.nMonitorStateID
  4. INNER JOIN PivotActiveMonitorTypeToDevice ON PivotActiveMonitorTypeToDevice.nPivotActiveMonitorTypeToDeviceID = ActiveMonitorStateChangeLog.nPivotActiveMonitorTypeToDeviceID
  5. INNER JOIN Device ON Device.nDeviceID = PivotActiveMonitorTypeToDevice.nDeviceID
  6. INNER JOIN ActiveMonitorType ON ActiveMonitorType.nActiveMonitorTypeID = PivotActiveMonitorTypeToDevice.nActiveMonitorTypeID
  7. WHERE PivotActiveMonitorTypeToDevice.nPivotActiveMonitorTypeToDeviceID = 3499
  8. AND ((dStartTime >= '2009-05-18' AND ISNULL(dEndTime, GETDATE()) <= '2010-04-22')
  9. OR (dStartTime <= '2010-04-22' AND ISNULL(dEndTime, GETDATE()) >= '2009-05-18')
  10. OR (dStartTime <= '2010-04-22' AND ISNULL(dEndTime, GETDATE()) >= '2010-04-22')
  11. OR (dStartTime <= '2009-05-18' AND ISNULL(dEndTime, GETDATE()) >= '2010-04-22')
  12. )
  13. ORDER BY dStartTime ASC;

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS