Having an issue trying to write the SQL to access the AF database
In order to access PI AF data from another data source using SQL queries, you'll want to use the PI OLEDB Enterprise. To run those queries from an ODBC connection, you'll want to use the PI ODBC Driver (installed on the same machine containing the Oracle Gateway) to connect to the PI SQL Data Access Server (can be installed on any machine; same machine needs to have PI OLEDB Enterprise installed), which will then run the PI OLEDB Enterprise queries.
Which portion of this are having problems with? I would suggest starting with PI SQL Commander (application included in the PI OLEDB Enterprise installation) to create the PI OLEDB Enterprise queries. Once those work, create the ODBC DSN and test it using the ODBC data source list in PI SQL Commander Lite (application included in the PI ODBC Driver installation). Then once that's confirmed to be working, try to connect from the Oracle Gateway.
Once you get to this step in the process, you could use this configuration guide to help you.
If we know which step of the process is giving you problems, and what the specific issue is, we can further assist.
Retrieving data ...