How do I create a stored procedure?

Posted on 2008-11-19
Last Modified: 2012-05-05
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
Question by:tupac1979
    LVL 60

    Accepted 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.
    LVL 11

    Expert Comment

    Create a Temp table for checking the last value retrieved.
    LVL 60

    Expert Comment

    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.
    LVL 2

    Expert Comment

    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...
    LVL 2

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now