Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQl Query to run at 6am

Author  Topic 

Jezz
Starting Member

1 Post

Posted - 2013-03-27 : 04:52:59
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

3608 Posts

Posted - 2013-03-27 : 06:24:10
Here is one way:

DATEDIFF(hh,CONVERT(DATETIME,CONVERT(VARCHAR,CONVERT(DATE,GETDATE())) + ' 06:00:00'),GETDATE())
Go to Top of Page
   

- Advertisement -