How to automatically generate a reminder email to the User on the 14th calendar day in Sql Server 2008?

I have a webpage through with NewsFeedback is submitted.
In the table, I have feedbackdate_submitted, feedbackdate_closed, userid, useremail,  information in the database.

I need to send a reminder email automatically on the 14th calendar day after the first time feedback is submitted. If feedback submitted on May1, then reminder email will generate on May14 to the user.  After then every 10th day, email reminder wil send to user as long as the feedback is not closed.

How to do that in sql server job?

Who is Participating?
Scott PletcherSenior DBACommented:
You'll have to add a "feedback_reminder_count" to that table (or put it in a different table), because you have to know the first feedback reminder vs. later than the first.  I'll assume that column's in the same table.

IF OBJECT_ID('tempdb.dbo.#reminders') IS NOT NULL
    DROP TABLE dbo.#reminders
--query to determine reminders that need sent today
SELECT t.feedbackdate_submitted, t.userid, t.useremail
INTO dbo.#reminders
FROM tablename t
    t.feedback_closed IS NULL AND
    ((t.feedback_reminder_count = 1 AND t.feedbackdate_submitted = DATEADD(DAY, -14, GETDATE())) OR
     ((DATEDIFF(DAY, t.feedbackdate_submitted, GETDATE()) - 14) % 10 = 0))

--...<<code to email the reminders goes here>>...

SET feedback_reminder_count = feedback_reminder_count + 1
FROM tablename t
INNER JOIN dbo.#reminders r ON
    r.userid = t.userid AND
    r.useremail = t.useremail
Leo TorresSQL DeveloperCommented:
You may need to enable procedure use in sql.

look Here

Create a job that calls dbo.sp_send_dbmail
pass it parameters needed
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.