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
Who is Participating?
chapmandewConnect With a Mentor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.