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
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you want it in Java?
Avatar of chaitu chaitu

ASKER

no i want in sql server.i want to exclude the records which are inserted in the last 1 hr.
Avatar of sameer2010
sameer2010
Flag of India image

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

Open in new window

Avatar of sameer2010
sameer2010
Flag of India image

Oops...page refresh issue. PorterPaul has already posted this.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image


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
Avatar of chaitu chaitu

ASKER

will it exclude records for last 1 hr  based on Timestamp ?
Avatar of PortletPaul
PortletPaul
Flag of Australia image

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())
Avatar of PortletPaul
PortletPaul
Flag of Australia image

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.
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

Try

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

Open in new window

Microsoft SQL Server 2008
Microsoft SQL Server 2008

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.

50K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo