Problem result sql query

Welcome to the forum, Theo.

See Wiki - how to post code on this forum. 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.

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.

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(_).