Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
So far we have given examples of extracting data from a single table within PI but as those familiar with SQL will know, it is possible to join tables together to extract data from both tables in a single query.
Let us look at 2 tables from within PI, PIcomp (data/events) and PIpoint (tag attributes etc).
What we are going to do is retrieve the current value for the PI tag SINUSOID from PIcomp and get it's descriptor from PIpoint.
How will your SQL query look for this?
SELECT cmp.Value, pnt.descriptor FROM PIcomp cmp, PIpoint pnt WHERE cmp.tag = 'SINUSOID' AND cmp.tag = pnt.tag AND cmp.time = Date('*')
And to implement:
Code:Sub RetrieveValues()
If PIODBC_Connection Then Dim RS As ADODB.Recordset Set RS = New ADODB.Recordset Set RS = Conn.Execute("SELECT cmp.Value, pnt.descriptor FROM PIcomp cmp, PIpoint pnt WHERE cmp.tag = 'SINUSOID' AND cmp.tag = pnt.tag AND cmp.time = Date('*')") RS.MoveFirst While Not RS.EOF Debug.Print RS.Fields("value").Value & " : " & RS.Fields("descriptor").Value RS.MoveNext Wend Set RS = Nothing Else
End If
End Sub
Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System. We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ or contact OSIsoft vCampus for more details.
|