Ask the Expert

SQL Server trigger vs. stored procedure to receive data notification

I am using SQL Server 2000, and I have a database field for warranty expiration dates. I would like to know 30 days in advance when an item is about to go out of warranty. How would I go about creating a trigger to inform me of this?

    Requires Free Membership to View

A trigger would not work well in this example. A trigger executes when you perform an INSERT/UPDATE/SELECT command on a row or rows of data, and it is typically only used in relation to the data just updated. If the data is not updated, no trigger would fire, either. In your case, it seems that you need something like a notification, instead.

I would develop a stored procedure to return the count of items too close to the warranty expire date. In the query, I would use the DATEDIFF function to find out if there are any matching rows. Then, I would create a scheduled job and have an email sent to me if the count is greater than zero.

This was first published in October 2008

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: