sql

by mattias on March 12th, 2010
No notes
Syntax: SQL
Show lines - Hide lines - Show in textbox - Download
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;

Leave a Reply

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

Subscribe to this comment feed via RSS