Applies to :
PcVue all versions with HDS. |
||
|
||
Summary :
This article explains how to use Chrono for making SQL queries. |
||
|
||
Details :
In HDS data storage, the TS field is optional and should not be used in a SQL query as it is not indexed. The Chrono field should be used instead.SolutionHere is an example of what not to do to retrieve the data between 9:00 and 10:00. SELECT Chrono,Name,Value,Quality,TSFROM TRENDTABLE1 where TS > convert ( datetime , ‘2007-05-25 09:00:00’ , 121 ) and TS < convert ( datetime , ‘2007-05-25 10:00:00’ , 121 ) order by Chrono The response time will be dependent of the size of the database (fast if <1GB, long if >2GB, time out if >4 GB). Here is an example of how to do it properly. Declare @LocalStartDate as datetime; SET @LocalStartDate = ‘2022-05-05 19:24:00’; SELECT Chrono,Name,Value,Quality,TS FROM TRENDTABLE1 This looks more complex but the query uses the native indexes of the tables. The result of the request is therefore almost independent of the size of the database. See also KB article KB479 to know more about How to generate TS column if it is absent from the database. Finally it can be gathered all together like that: Declare @LocalStartDate as datetime; SET @LocalStartDate = ‘2022-05-05 19:24:00’; SELECT CONVERT(datetime, SWITCHOFFSET(CONVERT(datetimeoffset, DATEADD(second,((chrono-116444736000000000)/10000000), convert(datetime,’1970-01-01 00:00:00′,121))),DATENAME(TzOffset, SYSDATETIMEOFFSET()))) as LocalTSCalculated,Name,Value,Quality FROM TRENDTABLE1 |
||
|
||
|
Created on: 14 Sep 2010 Last update: 16 May 2024