You can use a combination of tools. I'll give you an abridged list of the ones I use.
First, I assume you have database mail configured.
Second, you can trigger a lot of run-of-the-mill alerts using SQL Server Alerts. You can also run a stored procedure using a scheduled job (say every five minutes or some interval like that) and fire the user counters which will trigger SQL Server Alerts. When an alert happens, you can also execute a job in addition to notifying operators. If you know WMI, you can use Alerts to get to PerfMon counters.
Third, you can use SQL Server Extended Events, but they are more complicated and require a good understanding of the database engine and hand coding because there is very little in the way of GUI.
Finally, you can just schedule a stored procedure to run on a regular basis, allow it to collect metrics from the DMVs (database management views) and then send the email directly from the stored procedure.
Specifically for your situation, I might suggest you run sys.dm_os_performance_counters on a regular basis (scheduled job/stored procedure) and cache it in a metadata table, then use that for analysis.
Also, getting CPU usage information in SQL Server is not the easiest thing in the world because CPU stats can change on such a finely-granular timescale. Try this article for a good overview of how it works. Perhaps look at "free pages" to get you 70% RAM figure.
I base my idea on generating the records for each interval.For this I use master..spt_values
.( you can use anything else, that generate a list of numbers 0,1,2...).
So , for interval 60-46
, generate 3
(frequency) records.Those records have the starting point = the event date - 60 days. (This is the date when you start to send emails)
DECLARE @dtCurrentDT AS DATETIME ;
SET @dtCurrentDT = '20160402';
--SET @dtCurrentDT = '20160403';
WITH EventsCTE AS
( SELECT '20160601' AS EventPromotion)
,RemindersCTE AS
(SELECT 60 aS DayFrom,46 AS Dayto, 3 AS Frequent UNION ALL
SELECT 45,37,3 UNION ALL
SELECT 36,31,6)
SELECT
R.DayFrom
,R.Dayto
,R.Frequent
,DATEADD(DAY,
((R.DayFrom-R.DayTo + 1)/ R.Frequent) * CA.number ,
DATEADD(DAY,-R.DayFrom,E.EventPromotion)) AS StartDateEvent_ToSendMail
--,CA.number
--,DATEADD(DAY,((R.DayFrom-R.DayTo + 1)/ R.Frequent) * CA.number , @dtCurrentDT) AS RemainderDay
--,DATEADD(DAY,-R.DayFrom,E.EventPromotion) AS Event_StartDate
FROM
RemindersCTE AS R
CROSS APPLY
(SELECT TOP(R.Frequent)
V.number
FROM
master..spt_values AS V
WHERE
V.type ='P'
ORDER BY
V.number ASC
)CA
CROSS JOIN EventsCTE AS E
WHERE
DATEADD(DAY,
((R.DayFrom-R.DayTo + 1)/ R.Frequent) * CA.number ,
DATEADD(DAY,-R.DayFrom,E.EventPromotion))
>= @dtCurrentDT;
My output is :
DayFrom Dayto Frequent StartDateEvent_ToSendMail
60 46 3 2016-04-02 00:00:00.000
60 46 3 2016-04-07 00:00:00.000
60 46 3 2016-04-12 00:00:00.000
45 37 3 2016-04-17 00:00:00.000
45 37 3 2016-04-20 00:00:00.000
45 37 3 2016-04-23 00:00:00.000
36 31 6 2016-04-26 00:00:00.000
36 31 6 2016-04-27 00:00:00.000
36 31 6 2016-04-28 00:00:00.000
36 31 6 2016-04-29 00:00:00.000
36 31 6 2016-04-30 00:00:00.000
36 31 6 2016-05-01 00:00:00.000
Best Answer
The quickest solution I can think of would be to create on your specific table an after insert trigger where, based on your conditions (the error no..etc), you'd call the system procedure msdb.dbo.sp_send_dbmail to send a custom email.
You'd have first to configure the mail (create a profile and test it). I don't really think there's a simpler way.
I think that you could create an alert based on a custom error number. But this means that you'll have to modify your current code that inserts data in that table to throw this custom error no, to be able to see the alert.