Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 409 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
OSIsoft PI System SpecialistsPI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!
|