Need to decide between a trigger, CASE, END-ELSE to write to a table & DATEDIFF()
Bear with me here. I used the script found at: http://sqlfool.com/2008/11/replication-monitor/
I want to test to see if an entry been made from the server over the last 30 minutes?
If the answer is NO, then write that entry to a different table and possibly alert us.
The following query me the difference in minutes between right now and the very last entry for the server Test1 under 'monitorDate', a datetime field.
SELECT TOP 1 DATEDIFF (minute, (SELECT TOP 1 (SELECT MAX(monitorDate)
FROM dba_replicationMonitor)), GETDATE())
FROM MASTER.dbo.dba_replicationMonitor
WHERE publicationName = 'Test1'
I can't figure out how to say 'if that number returned is mor开发者_如何学Goe than 5, pass the serverName and monitorDate to a different table.
Any suggestions to point the way would be greatly appreciated. Thanks.
Couldn't you just derive your results and insert them if they match your needs?
INSERT INTO WHATEVERTABLE (serverfield, datefield)
SELECT result.server, result.date
FROM (YOURQUERY) result
WHERE result.yourresult > 5
精彩评论