• Will this run every 4 seconds from the time the stored procedure is called in the program?

    The stored procedure will execute indefinitely, but every 4 seconds it will deliver a new resultset. Compile it in your environment and try it out.

    Also the results from the select should go into xls file, may be appended every 4 seconds... Is this possible?

    If you want to write the resultset to an Excel file then you probably would want to write the resultset to a table every 4 seconds, and then have a separate process pull the data in that table periodically, but far less than every 4 seconds.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato