• @ salokbi,

    You are NOT going back 7 minutes, you are going back anywhere between 7m0s and 7m59.999s

    If you script initiates at 12:07:45 you will get all records from 12:00:00 - that is NOT 7 minutes,

    If it next runs at 12:14:59 you will get all the records from 12:07 - records from 12:07:00 to 12:07:45 will appear in both reports

    if it next runs as 12:15:01 it will get all records from 12:08:00. any records that appeared between 12:07:46 and 12:07:59 will not be picked up.

    2 seconds difference in the execution start makes a hole minutes difference to the records selected. [technically 1 millisecond is all that is needed - 12:14:59.999 to 12:15:00.0000]

    if it is a date datatype then how can it go back 7 minutes - there is no time element?

    Generally to create a stored procedure, write the code you would normally write in your query then wrap the query in

    CREATE PROCEDURE <ProcedureName> AS

    BEGIN

    <your code goes here...>

    END

    and execute the query; this will create the stored procedure. You can then run the stored procedure using

    EXEC <ProcedureName>

    There is loads more to it if you need to pass in parameters or run the proc under specific user priveleges but this is the basics.

    The stored procedure can execute a number of separate SQL statements as a single process. e.g. define a variable, get the value from the database, run a query to return a result set and update the records to mark them as output.

    you can also return multiple results sets from a stored procedure, but you need to take care if these are being consumed downstream by a .NET component or similar (SSIS task, Access procedure etc) as you need to define which result set will be used.