SELECT ID,VALUEAsReal, RecordTime, RecordId
FROM CDBHISTORIC
WHERE RecordTime > {ts '2019-10-17 13:00:00'} AND ID = 40776 OR ID = 26114
I am trying to filter the results from CDBHISTORIC like so, I have also tried BETWEEN the chosen date and current timestamp but everything is giving me the same error. It returns all values from those ID's normally with out timestamp filtering.
Error in SQL statement: ODBC-call returned [-1] : [HY000][0][Control Microsystems][ClearSCADA database driver]Historic query not constrained by object, or could not be optimised efficiently
What am I doing wrong?
Solved! Go to Solution.
Never god **bleep** mind, I literally found the solution two seconds after I posted this. Here is the correct SQL
SELECT ID,VALUEAsReal, RecordTime, RecordId
FROM CDBHISTORIC
WHERE RecordTime > {ts '2019-10-17 13:00:00'} AND (ID = 40776 OR ID = 26114)
You have to put the parenthesis () for the other filters: (ID = 40776 OR ID = 26114)
*sigh* why is my life like this.
Some documentation about this can be found here: http://34.236.135.167/Help/Default.htm#SQLGuide/BuildtheSubClauseList.htm%3FTocPath%3DCore%2520Refer...
Never god **bleep** mind, I literally found the solution two seconds after I posted this. Here is the correct SQL
SELECT ID,VALUEAsReal, RecordTime, RecordId
FROM CDBHISTORIC
WHERE RecordTime > {ts '2019-10-17 13:00:00'} AND (ID = 40776 OR ID = 26114)
You have to put the parenthesis () for the other filters: (ID = 40776 OR ID = 26114)
*sigh* why is my life like this.
Some documentation about this can be found here: http://34.236.135.167/Help/Default.htm#SQLGuide/BuildtheSubClauseList.htm%3FTocPath%3DCore%2520Refer...
AND takes precedence over OR, so your original query was really
Give me all historic where:
* RecordTime > {ts '2019-10-17 13:00:00'} AND ID = 40776
* OR give me all data for ID = 26114
When you added the brackets you made the logical part change
Discuss challenges in energy and automation with 30,000+ experts and peers.
Find answers in 10,000+ support articles to help solve your product and business challenges.
Find peer based solutions to your questions. Provide answers for fellow community members!