• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

How do I create a stored procedure?

I have a stored procedure that will fetch a record by todays date when the status is equal to '3'. My problem is I would like the procedure to run as a job every 5 minutes but I only want it to get the record one time. I cannot add another field to the database to track this. What is the simplest way to one record that is equal to todays date and status 3 and when it runs again it will not fectch the same record?

Any help is appreciated
1 Solution
You'll have to track it somehow, either through the use of keeping track of the last id returned, or through a table of IDs that you have already returned.
Create a Temp table for checking the last value retrieved.
but you'll have to keep track of the last value returned...and the temp table will go out of scope as soon as the proc is returned.
I don't know what you do with that record, but if you put some data somewhere as soon as you have that record the first time, you could do something like this:

IF NOT EXISTS (SELECT * FROM tblResult WHERE column1 = 'abcde')
         << Do trick here >>

This solves your kind of problems for me in most scenario's...
you have to create a dummy table for the fetched records.  When your procedure fetch a record, maintain a copy in this dummy table with the unique id of fetched record.  Next time when procedure fetches records, check the dummy table for existing records and ignore the matches.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now