# Problem result sql query

**URL:** <https://forum.inductiveautomation.com/t/problem-result-sql-query/86345>\
**Category:** Ignition\
**Created:** [February 26, 2024, 8:52am UTC](https://forum.inductiveautomation.com/t/problem-result-sql-query/86345 "2024-02-26T08:52:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 26, 2024, 11:13am UTC](https://forum.inductiveautomation.com/t/problem-result-sql-query/86345/2 "2024-02-26T11:13:29Z")

</div>

Welcome to the forum, Theo.

See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). There's a pencil icon below the post so you can edit. You can also use Python's triple quotes to wrap your SQL for readability.

```auto
CodeMat = system.tag.readBlocking(['[default]Cde_Matiere'])[0].value

essai =system.dataset.toDataSet(system.db.runPrepQuery("""
    SELECT DISTINCT CodeStockage 
    FROM tStockageInfo 
    WHERE CodeMatiere = (?)""", 
    [CodeMat])
)

essai2 = system.dataset.toDataSet(system.db.runQuery("""
    SELECT DISTINCT CodeStockage 
    FROM tStockage 
    WHERE CodeGroupe=1 
      AND NOT CodeStockage IN (
        SELECT CodeStockage FROM tStockageInfo
      )"""
    )
)

essai3 = system.dataset.appendDataset(essai2, essai)

```

The code below won't work.

```auto
system.db.runPrepQuery("""
    SELECT DISTINCT LibelleL1 
    FROM tStockage 
    WHERE CodeStockage IN ((?))", 
    [essai3] 
)

```

The prepared query can't take a dataset or even a list.  
I think the best solution would be to convert the dataset to a comma separated string using a join function. Then pass that into the IN(\_).

---

_[View the full topic](https://forum.inductiveautomation.com/t/problem-result-sql-query/86345)._
