AnsweredAssumed Answered

PI SQL Client query to get Attribute data based on Event Frame timestam

Question asked by Danny Dijke on Oct 9, 2018
Latest reply on Oct 11, 2018 by vkaufmann

Hello,

I'm having some difficulties to build the right query to retrieve data of an attribute based for a timestamp related to an Event Frame. The attribute is not part of the Event Frame itself.

 

This is what I tried:

 

SELECT e.Name, ea.Name Attribute, ef.StartTime, s.Value, ea.UnitOfMeasure

FROM [Master].[Element].[Element] e

INNER JOIN [Master].[Element].[Attribute] ea ON ea.ElementID = e.ID,

(SELECT StartTime FROM [Master].[EventFrame].[EventFrame] WHERE Name = 'EFName') ef

CROSS APPLY [Master].[Element].[GetSampledValue] (ea.ID, ef.StartTime) s

WHERE e.Template = 'ElementTemplate'

AND ea.Name IN ('Attribute1', 'Attribute2')

 

Result: [SQL Query Engine] Object reference not set to an instance of an object.

 

When just coping the starttime as a string, the result is fine:

 

SELECT e.Name, ea.Name Attribute, ef.StartTime, s.Value, ea.UnitOfMeasure

FROM [Master].[Element].[Element] e

INNER JOIN [Master].[Element].[Attribute] ea ON ea.ElementID = e.ID,

(SELECT StartTime FROM [Master].[EventFrame].[EventFrame] WHERE Name = 'EFName') ef

CROSS APPLY [Master].[Element].[GetSampledValue] (ea.ID, '01-Oct-18 09:02:52') s

WHERE e.Template = 'ElementTemplate'

AND ea.Name IN ('Attribute1', 'Attribute2')

 

How do I add the event frame starttime as parameter to the GetSampledValue function?

Outcomes