YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Usings Joins in PI-ODBC Options · View
RJK Solutions
#1 Posted : Wednesday, November 26, 2008 9:32:28 AM
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
Sponsor  
 

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.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.