IN SQL query to run from 6 am today

Jezz

Member
Join Date
Dec 2002
Location
Kendal
Posts
399
[FONT=Verdana, Arial, Helvetica][FONT=Verdana, Arial, Helvetica]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. Any one got any ideas?

Thanks

[/FONT][/FONT]
 
Bit late to the party but...

Not sure what 'flavour' of SQL you are using but how about something like

Code:
[FONT=Verdana, Arial, Helvetica][FONT=Verdana, Arial, Helvetica][SIZE=2]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'[/SIZE][/FONT][/FONT]
[B]AND CAST(DateTime AS DATE) = CAST(GETDATE() AS DATE) 
AND datename("hour",[/B][B][B]DateTime [/B])>'6')[/B]
 

Similar Topics

Good Evening, I'm loading a recipe into a Rockwell ControlLogix or CompactLogix CPU via Excel, this is all working fine. Is there anyway I can...
Replies
7
Views
2,042
Hi, I have a question about SQL. This question is a little to much on the IT side I suppose, but I will give it a try anyway as I do not have an...
Replies
6
Views
2,518
Hi there, I use Indusoft IWS8.0 & I have created a sample Production data Date&time, MachineNo,Production Data with SQL Server 2008 DB. Need to...
Replies
1
Views
1,877
Hello, For my general information and knowledge, how is querying and storing data from a AB PLC (Compact or Control Logix) typically...
Replies
15
Views
7,368
Goodevening all... I have a Redlion PTV and Graphite with built in webserver... I can create the simple default.htm page... drag in tags to...
Replies
1
Views
1,907
Back
Top Bottom