Query of 2 databases


I need a query to get datas from 2 diferent databases and later show them in a table. Does anybody know which is exactly the syntax in Ignition?


The problem is you can’t query two different databases in a single SQL query in binding unless the 2 databases are in the same database server. If they are not, you will have to generate the dataset in scripting. In scripting you can query two different databases and combine the results into one. The script would look something like this:[code]header = [“col1”, “col2”]
data = []

rs = system.db.runQuery(“SELECT * FROM FirstTable”)
for row in rs:
data.append([row[0], row[1]])

rs = system.db.runQuery(“SELECT * FROM SecondTable”)
for row in rs:
data.append([row[0], row[1]])

newDS = system.dataset.toDataSet(header, data)[/code]You can run this script when the window opens or when someone presses a button or on a timer. I know this doesn’t give you exactly what you need so if you need more help please let us know.

Thanks Travis! Finall I’ve done it in a timer script and runs perfect.