Skip to Content
0
Former Member
Sep 12, 2007 at 03:52 AM

Passing a time variable

43 Views

Post Author: danderson

CA Forum: Data Connectivity and SQL

Hi

I am using a command to extract data from history tables of data. I have got the query with a fixed time variable (ie now - 12 hours) but I cant seem to get it to work passing parameters in. This is what works so far:

SET QUOTED_IDENTIFIER OFFSELECT * FROM OpenQuery(INSQL, "SELECT DateTime = convert(nvarchar, DateTime, 113), &#91;T1 Distance&#93;, &#91;T1 kWh&#93;, &#91;T1 Speed&#93; FROM Runtime.dbo.AnalogWideHistory WHERE wwVersion = 'Latest' AND wwRetrievalMode = 'Cyclic' AND wwResolution = 15000 AND DateTime >= DateAdd(hh,-12,GetDate()) AND DateTime <= GetDate()")

I have done it like this on similar queries, but I can't seem to crack it on this one. This is what I have tried (in various forms!!!) that doesnt work

SET QUOTED_IDENTIFIER OFFSELECT * FROM OpenQuery(INSQL, "SELECT DateTime = convert(nvarchar, DateTime, 113), &#91;T1 Distance&#93;, &#91;T1 kWh&#93;, &#91;T1 Speed&#93; FROM Runtime.dbo.AnalogWideHistory WHERE wwVersion = 'Latest' AND wwRetrievalMode = 'Cyclic' AND wwResolution = 15000 AND DateTime >= {?StartDate} AND DateTime <= {?EndDate}")

I then have a date / time variable for StartDate and EndDate

Can anyone give me any hints??

Thanks

Dave A