3 Replies Latest reply on Feb 23, 2016 8:59 AM by gregor

    How to query to get Element Attributes and Tag associated with Element

    QasimGulzar

      I want to List Pi-Elements (Assets) for example i have element with name "TANK" now to list all of its attributes and tag name associated with attributes of this tank. please guide me fetch this data from sql server.

       

      thank you.

        • Re: How to query to get Element Attributes and Tag associated with Element
          gregor

          Hello Qasim,

           

          Please see the following PI OLEDB Enterprise query example which is making use of the built in GetPIPoint function. Please make sure to replace <YourDatabase> with the name of your AF database.

           

          SELECT ea.name, gp.Tag
          FROM [<YourDatabase>].[Asset].[ElementHierarchy] eh
          INNER JOIN [<YourDatabase>].[Asset].[ElementAttribute] ea ON ea.ElementID = eh.ElementID
          CROSS APPLY [<YourDatabase>].[Asset].[GetPIPoint] 
          (
             ea.ID -- ElementAttributeID
          ) gp
          WHERE eh.Name = 'TANK'
          OPTION (FORCE ORDER, EMBED ERRORS)
          
          1 of 1 people found this helpful
            • Re: How to query to get Element Attributes and Tag associated with Element
              QasimGulzar

              HI,

              thank you for your response this works for oledb enterprise, now I want to execute this query from python. right now I can query on data archive. Yes i can under stand what is difference between these store, below is my code please guide me now how I can query on PIAF using python

               

               

              db_cmd = """SELECT * FROM piarchive..picomp2 WHERE tag = 'SEC.CT06.SG.CT6-TRB-EX-SEI-5.V.none.2xMagnitude'"""

                  # db_cmd = """SELECT * FROM pipoint"""1

                  oRS.ActiveConnection = "Provider=PIOLEDB; Data Source=localhost; Integrated Security=True"

                  oRS.Open(db_cmd)

               

              now i want to change this connection string for PIAF please guide me.

                • Re: How to query to get Element Attributes and Tag associated with Element
                  gregor

                  Hello Qasim,

                   

                  You are connecting against PI OLEDB (Classic) Provider which is a different product. You need to connect though PI OLEDB Enterprise.

                  The connection string very much depends on your environment but the following may work for you if you do have PI OLEDB Enterprise installed.

                   

                  oRS.ActiveConnection = "Provider=PIOLEDBENT; Data Source=localhost; Integrated Security=True"
                  

                   

                  Please don't forget to change db_cmd to a query that will work with PI OLEDB Enterprise.

                  1 of 1 people found this helpful