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

    By submitting your registration information to SearchSQLServer.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSQLServer.com is governed by our Terms of Use. You may contact us at [email protected].

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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.