--LIVE VIEW QUERIES --Example 1 SELECT * FROM Live WHERE TagName = 'M100.LT.PV' --Example 2 SELECT DateTime, TagName, Value FROM Live WHERE TagName = 'M100.LT.PV' --Example 3 --Notice the Null value retrieved for the string. SELECT DateTime, TagName, Value FROM Live WHERE TagName IN ('M100.LT.PV', 'Agitator_001.Malfunction', 'Agitator_001.Malfunction.msg') --Example 4 --Use of vValue. SELECT DateTime, TagName, Value, vValue FROM Live WHERE TagName IN ('M100.LT.PV', 'Agitator_001.Malfunction', 'Agitator_001.Malfunction.msg') --HISTORY VIEW QUERIES --Example 5 --With no time window defined, records are retrieved for the last hour. SELECT DateTime, TagName, Value FROM History WHERE TagName = 'Agitator_001.Speed.PV' --Example 6 --5 minute fixed time window. SELECT DateTime, TagName, Value FROM History WHERE TagName = 'Agitator_001.Speed.PV' AND DateTime > 'January 1, 2013 12:00:00.000' AND DateTime <= 'January 1, 2013 12:05:00.000' --Example 7 --Time window from a fixed start time until now. SELECT DateTime, TagName, Value FROM History WHERE TagName = 'Agitator_001.Speed.PV' AND DateTime > 'January 01, 2013 12:00:00.000' AND DateTime <= Getdate() --Example 8 --Relative time window, from 10 minutes ago until now. SELECT DateTime, TagName, Value FROM History WHERE TagName IN ('Agitator_001.Speed.PV','Agitator_002.Speed.PV' ) AND DateTime > Dateadd(mi, -10, Getdate()) AND DateTime <= Getdate() --Example 9 --Use of wildcards. SELECT DateTime, TagName, Value, vValue FROM History WHERE TagName LIKE 'Agitator%' AND DateTime > Dateadd(mi, -10, Getdate()) AND DateTime <= Getdate() --Example 10 --Open query. SELECT * FROM OpenQuery (INSQL,' SELECT DateTime, [M100.LT.PV], [Agitator_001.Malfunction] FROM WideHistory WHERE DateTime > Dateadd(ss, -120, Getdate()) AND DateTime <= Getdate() ')