# RunQuery with second Database

**URL:** <https://forum.inductiveautomation.com/t/runquery-with-second-database/20744>\
**Category:** Ignition\
**Tags:** ignition78, database\
**Created:** [November 11, 2018, 10:39am UTC](https://forum.inductiveautomation.com/t/runquery-with-second-database/20744 "2018-11-11T10:39:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamerplc](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@tamerplc](https://forum.inductiveautomation.com/u/tamerplc)\
**Post date:** [November 11, 2018, 10:39am UTC](https://forum.inductiveautomation.com/t/runquery-with-second-database/20744/1 "2018-11-11T10:39:32Z")

</div>

i have a button with below script action performed to run query from Demo2 database while the default database is “Demo” . i got error that caused by MySQLSyntaxErrorException: Table ‘demo2.vw\_wodetails’ doesn’t exist

```auto
table = system.db.runQuery("SELECT DISTINCT wo_id from demo2.vw_WODetails where process_id ='{Root Container.Tab Strip.selectedTab}'")
system.tag.write("Result",table)

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 11, 2018, 2:47pm UTC](https://forum.inductiveautomation.com/t/runquery-with-second-database/20744/2 "2018-11-11T14:47:00Z")

</div>

`runQuery` accepts a database parameter separate from your query parameter: [https://docs.inductiveautomation.com/display/DOC79/system.db.runQuery](https://docs.inductiveautomation.com/display/DOC79/system.db.runQuery)

---

<div class="post-metadata">

**Author:** ![tamerplc](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@tamerplc](https://forum.inductiveautomation.com/u/tamerplc)\
**Post date:** [November 12, 2018, 8:52am UTC](https://forum.inductiveautomation.com/t/runquery-with-second-database/20744/3 "2018-11-12T08:52:09Z")

</div>

> [@tamerplc](#):
>
> system.tag.write("Result",table)

Thanks a lot Kevin , it working .  
i got anther error  
This script working find without property reference

```auto
table1=system.db.runQuery("select * from [IONSTAGING].[mes].[MES_WMS_INBOUND] WHERE ( Charindex('120000637',CAST(INTF_MESSAGE AS VARCHAR(MAX)))>0 ) order by INTF_CREATION_DATE desc","IONDB",)
system.tag.write("result1",table1)

```

Same script with property reference ,gave me an error  
caused by SQLServerException: Incorrect syntax near 'Dropdown'.`

```auto
table1=system.db.runQuery("select * from [IONSTAGING].[mes].[MES_WMS_INBOUND] WHERE ( Charindex('event.source.parent.getComponent('Dropdown').selectedStringValue',CAST(INTF_MESSAGE AS VARCHAR(MAX)))>0 ) order by INTF_CREATION_DATE desc","IONDB",)
system.tag.write("result1",table1)

```

what's my mistake ☹

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [November 12, 2018, 10:04am UTC](https://forum.inductiveautomation.com/t/runquery-with-second-database/20744/4 "2018-11-12T10:04:09Z")

</div>

Your quotes don’t match: you’re using single quotes as SQL argument, and in the argument, you use single quotes again to get the `Dropdown` component.

The best way to solve this is to first get the selected value from the dropdown, and later plug it into the query.

Splitting stuff over multiple lines also makes it easier to debug, as you know what line it’s happening on.

---

<div class="post-metadata">

**Author:** ![tamerplc](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@tamerplc](https://forum.inductiveautomation.com/u/tamerplc)\
**Post date:** [November 12, 2018, 10:25am UTC](https://forum.inductiveautomation.com/t/runquery-with-second-database/20744/5 "2018-11-12T10:25:40Z")

</div>

Thanks Sanderd,  
it’s ok now based in your advise and query working , but the result of the table only table header without data on the rows .
