PROBLEM
The SMScounter.Counter
is used to accumulate usage from a service. The service has a programmatic cap of 1000. I would like to alert users when this cap is breached.
TABLE CREATE
CREATE TABLE [dbo].[SMSCounter](
[Counter] [int] NOT NULL,
[CounterDate] [datetime] NOT NULL )
EXAMPLE DATA
380, 2012-09-10 00:00:00.000
177, 2012-10-14 00:00:00.000
999, 2012-11-16 00:00:00.000
JOB SCRIPT
The script below is my attempt to create a scheduled job that will check every hour if the SMScounter.Counter
is greater than 950.
USE DATABASEname
select (Counter) as CHECKVALUE from SMSCounter where smscounter.CounterDate = DATEADD(dd, DATEDIFF(dd, 0, GETDATE()),0)
IF CHECKVALUE > 950
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@recipients=N'scott@mydomain.com',
@body='1000 Daily SMS cap near',
@subject ='1000 Daily SMS cap near',
@profile_name ='SCOTT',
@query =
'USE DATABASEname
(select * from SMSCounter where CounterDate = GETDATE())'
END
QUESTIONS
How can I format
GETDATE
to examinedd/mm/yy
and ignore the time part when readingSMScounter.CounterDate
? (script above edited , works now).How can I get the
IF
statement to work to compareCHECKVALUE
to 950?
I'm using SQL Server 2008 standard edition.