Avatar of chaitu chaitu
chaitu chaituFlag for India asked on

write query so that it should NOT include any records within the last hour

how to write query so that it should NOT include any records within the last hour
 

 job_date
9/3/2013 11:45:55 PM
9/3/2013 11:47:18 PM
9/3/2013 11:49:34 PM
9/3/2013 11:51:01 PM
9/3/2013 11:54:44 PM
9/2/2013  10:11:11 AM

Open in new window

Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Peter Chan

8/22/2022 - Mon
Peter Chan

Try
 ... job_date between dateadd(hh,-1,GETDATE()) and getdate()

Open in new window

ASKER CERTIFIED SOLUTION
PortletPaul

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
CEHJ

Do you want it in Java?
ASKER
chaitu chaitu

no i want in sql server.i want to exclude the records which are inserted in the last 1 hr.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
sameer2010

You can use this
select * from your_table where 
job_date < dateadd(hh,-1,getdate())

Open in new window

sameer2010

Oops...page refresh issue. PorterPaul has already posted this.
CEHJ


no i want in sql server.i want to exclude the records which are inserted in the last 1 hr.
In that case, please don't post in Java TA - it just wastes people's time
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
chaitu chaitu

will it exclude records for last 1 hr  based on Timestamp ?
PortletPaul

A SQL Server timestamp field has nothing to do with dates or times (despite the name).

What type of field is [job_date]?

----
assuming job_date isn't a timestamp field:

if you want higher level of sub-second precision than GETDATE() you could use SYSDATETIME but I doubt that is necessary, i.e.

where job_date < dateadd(hour,-1,SYSDATETIME() )

see notes at: GETDATE (Transact-SQL)

you could also compare these results:
SELECT dateadd(hour,-1,GETDATE()), dateadd(hour,-1,SYSDATETIME())
PortletPaul

nb: rowversion at SQL 2012 documents online:
"timestamp is the synonym for the rowversion data type"
"The timestamp syntax is deprecated. This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature."

In SQL Server "timestamp" was rather an unfortunate choice of term for something that provides a unique reference to a row, but which cannot be used to identify either date or time.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Peter Chan

Try

 ... job_date < dateadd(hh,-1,GETDATE())

Open in new window