How to restrict Select statement results to last 5 minutes?

Using SQL Server  - I have the following basic Select statement:

SELECT ReportInstanceID

FROM dbo.ReportInstance

WHERE Status = 'FAILED'

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

Any guidance would be appreciated!
newtontech4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JestersGrindCommented:
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.

Greg

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
newtontech4Author Commented:
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())

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

Greg

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

newtontech4Author Commented:
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...
0
newtontech4Author Commented:
hello - my apologies I accidentally accepted my response as the solution.  All credit should go to JestersGrind - 500 points.
0
Anthony PerkinsCommented:
The author made a mistake and needs to award points to JestersGrind.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.