How to restrict Select statement results to last 5 minutes?

Posted on 2011-10-27
Last Modified: 2012-05-12
Using SQL Server  - I have the following basic Select statement:

SELECT ReportInstanceID

FROM dbo.ReportInstance


I am only interested in the results within the last 5 minutes not the entire result set...

Any guidance would be appreciated!
Question by:newtontech4
    LVL 21

    Accepted Solution

    Is the time that the record is inserted into that table captured?  If there isn't a date time associated with an instance of a report you may be out of luck.  You could add an additional column, CreatedOn DATETIME with a DEFAULT of GetDate().  That should have minimal impact on existing code and give a date/time to filter by.



    Author Comment

    Thank you - in event the time the record is inserted into the table is captured would this be proper SQL syntax?

    (sorry by no means a SQL expert..)

    SELECT ReportInstanceID FROM dbo.ReportInstance WHERE Status = FAILED AND datefield >= dateadd(minute,-60,getdate())

    LVL 21

    Assisted Solution

    That would get everything within the last hour.  For the last 5 minutes, just change -60 to -5.



    Author Comment

    I've requested that this question be closed as follows:

    Accepted answer: 0 points for newtontech4's comment http:/Q_27418345.html#37038205

    for the following reason:

    solution provided...

    Author Comment

    hello - my apologies I accidentally accepted my response as the solution.  All credit should go to JestersGrind - 500 points.
    LVL 75

    Expert Comment

    by:Anthony Perkins
    The author made a mistake and needs to award points to JestersGrind.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

    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