SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQl Query to run at 6am
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jezz
Starting Member

1 Posts

Posted - 03/27/2013 :  04:52:59  Show Profile  Reply with Quote
Hi All,
I have a query that returs the last 8 hrs worth of data, what I need it to do is return the data from 6am that day

SET QUOTED_IDENTIFIER OFF
SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime = convert(nvarchar, DateTime, 21), [Line-Status]
FROM WideHistory
WHERE [Line-Status] IS NOT NULL
AND wwRetrievalMode = 'Delta'
AND wwVersion = 'Latest'
AND DateTime >= DateAdd(hh,-8,GetDate())
AND DateTime <= GetDate()")

So I need to replace the -8 with the time diff between 6am and now.

Thanks

Jezz

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 03/27/2013 :  06:24:10  Show Profile  Reply with Quote
Here is one way:

DATEDIFF(hh,CONVERT(DATETIME,CONVERT(VARCHAR,CONVERT(DATE,GETDATE())) + ' 06:00:00'),GETDATE())

Edited by - RickD on 03/27/2013 06:24:24
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000