NeoAer
NeoAer

Reputation: 327

Sending automatic email based on date in SQL Server

I'm doing a project. I'm new to coding and very new to SQL. I'm coding in C# / ASP.net and using Microsoft SQL Server. I was wondering if there was a way to automatically send emails to a user based on a recorded date column in a database.

Basically I have my application recording a time in one column of a database and the email in another column. Once that time column is 30 days old i want it to send an email to that user saying hey you account info is 30 days old go update it.

Upvotes: 2

Views: 2135

Answers (2)

Kenneth Garza
Kenneth Garza

Reputation: 1916

Current answers suggest to create a sql trigger to send an email. I disagree with this approach. Sql triggers are not a silver bullet, and do you really want to make your sql server responsible for emails as well?

Instead, I would generally recommend instead to create a timer or scheduled job with ASP.NET that will will run daily and pull all users that you're going to send an email to.

Then process that email at will.

Upvotes: 1

Whatamidoing
Whatamidoing

Reputation: 490

SQL Agent job is what you need. The job can run a stored procedure every day at a fixed time (or more frequently). The stored procedure that runs would then go check all the records with a date greater than 30 days.

Upvotes: 4

Related Questions