Can I customise my SQL query so that I can filter values for vValue? I get an error with the following query. If I use ‘and vValue = “Empty” I get all values with Empty but I want everything that is not “Empty”...
Can I customise my SQL query so that I can filter values for vValue? I get an error with the following query. If I use ‘and vValue = “Empty” I get all values with Empty but I want everything that is not “Empty”...
This is possible, but requires some slight refactoring of how the criteria is applied. The root issue is that SQL Server has richer SQL support than the proprietary, internal query processing for the time-series data. In most cases, these two query processors work together transparently and correctly, but sometimes SQL Server tries to "optimize" the processing and send too much of it to the Historian's query engine. Occasionally, the details of how that optimization is applied changes with SQL Server releases.
The way to address that is to give SQL Server clearer separation of the responsibilities using a "subquery". For example:
SELECT vValue FROM (
SELECT TagName, DateTime, vValue
FROM History
WHERE History.TagName IN ('UDM001.LotNumber')
AND wwRetrievalMode = 'delta'
AND wwQualityRule = 'Extended'
AND wwVersion = 'Latest'
AND DateTime >= DateAdd(hh,-8,GetDate())
AND DateTime <= GetDate())
) AllRows
WHERE vValue <> 'Empty'
Here the inner SELECT is processed by the Historian's internal query processor and then the native SQL Server query engine handles the outer filter on "vValue". In my example above I also removed some columns and table references which don't contribute to the results.