EcoStruxure Geo SCADA Expert Forum
Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).
Link copied. Please paste this link to share this article on your social media post.
Posted: 2019-11-07 03:31 AM . Last Modified: 2023-05-03 12:23 AM
>>Message imported from previous forum - Category:Scripts and Tips<<
User: <None>, originally posted: 2019-06-20 04:09:03 Id:455
I would like to Search through the point history of a site and extract the very first date and time that history starting collecting for the site. Does anyone have an SQL query that can do this?
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2019-11-07 03:32 AM
>>Responses imported from previous forum
Reply From User: adamwoodland, posted: 2019-06-20 23:00:16
How efficient do you need this to be?
If inefficient then you could just do "SELECT TOP(1) * FROM CDBHistoric WHERE Id = [your object id] ORDER BY RecordTime ASC", it might take a long time depending on how much data and how dense the data is. CDBHistoric is disk resident so performance also depends on disk speed (and is relatively slow).
If you need it to be efficient (i.e. multiple points or needing to run often), then you should first query CDBHistoricFile (which is memory resident), look for the oldest granule for that point id with at least one record, and then just query that specific granule for its oldest record, i.e.:
SELECT TOP( 1 ) FILEID, FILETYPE, STARTTIME FROM CDBHISTORICFILE WHERE OBJECTID = 3793274 AND RECORDCOUNT = 1 AND FILETYPE = 0 ORDER BY "StartTime" ASC
Then for the next query:
SELECT TOP( 1 ) RECORDTIME, VALUE FROM CDBHISTORIC WHERE ID = 3793274 AND FILEID = '0039E17A0000554AR' ORDER BY "RecordTime" ASC
(Where 0039E17A0000554AR is the FileId from the first query)
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2019-11-07 03:32 AM
>>Responses imported from previous forum
Reply From User: adamwoodland, posted: 2019-06-20 23:00:16
How efficient do you need this to be?
If inefficient then you could just do "SELECT TOP(1) * FROM CDBHistoric WHERE Id = [your object id] ORDER BY RecordTime ASC", it might take a long time depending on how much data and how dense the data is. CDBHistoric is disk resident so performance also depends on disk speed (and is relatively slow).
If you need it to be efficient (i.e. multiple points or needing to run often), then you should first query CDBHistoricFile (which is memory resident), look for the oldest granule for that point id with at least one record, and then just query that specific granule for its oldest record, i.e.:
SELECT TOP( 1 ) FILEID, FILETYPE, STARTTIME FROM CDBHISTORICFILE WHERE OBJECTID = 3793274 AND RECORDCOUNT = 1 AND FILETYPE = 0 ORDER BY "StartTime" ASC
Then for the next query:
SELECT TOP( 1 ) RECORDTIME, VALUE FROM CDBHISTORIC WHERE ID = 3793274 AND FILEID = '0039E17A0000554AR' ORDER BY "RecordTime" ASC
(Where 0039E17A0000554AR is the FileId from the first query)
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.