I don't think there is a construct in SQL Server that allows you to run a stored procedure when the value of data equals user defined value. The reason behind this is if something as such were to be made, the performance of SQL Server would be tremendously impacted.
I would instead recommend you to consider writing a Windows Service that periodically wakes up and checks whether there are any rows in your table that have expired and then invoke your intended stored procedure on them. I can give you a sample of how to achieve this if you would like.
EDIT: A sample implementation of Windows Service
Okay so as I said above, there is no way of being notified when a particular data has reached its expiry time. So instead of being in the push notification model, we are working in a pull notification model where we periodically query the database for expired rows (e.g. something like "SELECT id FROM t1 WHERE enddate = @todayDate"
)
Now the key part of this solution is we need a periodic service. This has been demonstrated in the another user's answer here. The method where we will do our SQL operations is private void timer_Elapsed(...)
.
private void timer_Elapsed(object sender, System.Timer.ElapsedEventArgs e)
{
// since I am not sure whether you are accessing your database using ADO.NET
// (i.e. SqlConnection, etc.) or Entity Framework (i.e. DbContext),
// I will assume ADO.NET from here on
// retrieve all rows that have expired
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
var command = new SqlCommand("SELECT id FROM t1 WHERE enddate = @todayDate", connection);
var paramDate = new SqlParameter("@todayDate", DateTime.Now.Date);
command.Parameters.Add(paramDate);
var reader = command.ExecuteReader();
while (reader.Read())
{
var storedProcCommand = new SqlCommand("EXEC CleanUpExpiredRow @id", connection);
var paramId = new SqlParameter("@id", reader.GetInt32(0));
storedProcCommand.Parameters.Add(paramId);
command.ExecuteNonQuery();
}
}
}
NOTE None of this code is tested.