Is there anyway you can build a query like you would in sql to pull data ?
What im trying to do is get the timestamp, building Name , section , sensor number when the sensor has a state = "Error."
How do you want to consume the results of this query, and in what type of application context? You could do something like this using PI OLEDB Enterprise to execute a SQL query against a PI AF hierarchy, and return this type of data in the result set. The caveats attached to this answer are that you have an appropriate AF structure implemented, and that you have the PI Data Access components as well as a PI System Access license to use them in production.
PI ProcessBook has the capabilities of querying relational databases as an ODBC client. You can find more information here: PI ProcessBook
As John Messinger suggested, you could use the PI OLEDB Ent provider to retrieve this information from AF provided that you have this information readily available in AF.
Retrieving data ...