Question : How do trigger an automatic e-mail alert that is based on a date field in an SQL database?

I am creating a database of IT employees with a "Certification_Expiration_Date" field. This field is just a regular date field that has the expiration date of a certification expiration, such as a CCNA expiring on "2/20/08". I can't figure out how to trigger an email alert to be sent out of the database, notifying a user that the expiration date of their IT Certification is drawing near or has expired.

Answer : How do trigger an automatic e-mail alert that is based on a date field in an SQL database?

DECLARE @Email varchar(255)

DECLARE c1 CURSOR READ_ONLY
FOR
SELECT Email
FROM Employees
where Title='Project Manager'

OPEN c1

FETCH NEXT FROM c1

INTO @Email

WHILE @@FETCH_STATUS = 0

BEGIN

EXEC msdb.dbo.sp_send_dbmail
@recipients=@Email,
@body='Message Body',
@subject ='Message Subject',
@profile_name ='Database-mailProfile'

FETCH NEXT FROM c1
INTO @Email

END

CLOSE c1
DEALLOCATE c1

Random Solutions  
 
programming4us programming4us