# Simple dataset question

**URL:** <https://forum.inductiveautomation.com/t/simple-dataset-question/5098>\
**Category:** General Discussion\
**Created:** [September 4, 2012, 2:18pm UTC](https://forum.inductiveautomation.com/t/simple-dataset-question/5098 "2012-09-04T14:18:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikehill100](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mikehill100](https://forum.inductiveautomation.com/u/mikehill100)\
**Post date:** [September 4, 2012, 2:18pm UTC](https://forum.inductiveautomation.com/t/simple-dataset-question/5098/1 "2012-09-04T14:18:36Z")

</div>

I have a dataset that translates a code into words:

Code | Translation  
W | Weight  
L | Length  
P | Pressure

and so on.

Is there a way to script a translation from the dataset similar to using SQL?

SELECT Translation FROM table WHERE Code = “W”

If not, could I turn the dataset on its side?

Thanks

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 4, 2012, 3:04pm UTC](https://forum.inductiveautomation.com/t/simple-dataset-question/5098/2 "2012-09-04T15:04:36Z")

</div>

I wouldn’t use scripting or turn the dataset on its side. We have a lookup function in our expression language that you can use. So your example:

`SELECT Translation FROM table WHERE Code = 'W'`can easily be the following expression:`lookup({Path/To/Dataset}, "W", "", 0, 1)`It will return an empty string if “W” is not found. I would recommend putting these translations into a Client dataset tag so it is available everywhere.

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [September 4, 2012, 3:07pm UTC](https://forum.inductiveautomation.com/t/simple-dataset-question/5098/3 "2012-09-04T15:07:10Z")

</div>

I believe your use of the word “script” is throwing me off. Typically in this context that refers to Python scripting, not expressions, or SQL queries.

For expressions, see the [lookup](http://inductiveautomation.com/support/usermanuals/ignition/gen_logic_lookup.htm) function.

edit - looks like Travis beat me to it 🙂

---

<div class="post-metadata">

**Author:** ![mikehill100](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mikehill100](https://forum.inductiveautomation.com/u/mikehill100)\
**Post date:** [September 4, 2012, 5:11pm UTC](https://forum.inductiveautomation.com/t/simple-dataset-question/5098/4 "2012-09-04T17:11:29Z")

</div>

Would this work in an event script? I’m doing it behind a button push.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 4, 2012, 6:15pm UTC](https://forum.inductiveautomation.com/t/simple-dataset-question/5098/5 "2012-09-04T18:15:39Z")

</div>

No, it only works on bindings. In that case your best bet is to just loop though the dataset. You can make a global function (in the Script Modules) to do the lookup. In the designer, click on Project \> Script Modules. Add a new package called “ds”. Click on the new package and add the following script:`def lookup(dataset, code):
    import system
    data = system.dataset.toPyDataSet(dataset)
    for row in data:
        if row[0] == code:
            return row[1]
    return ""`You can call this in your script:`translation = app.ds.lookup(path.to.dataset, "W")`Just substitute the path.to.dataset to either a path to the dataset on the window or getting a tag value if you made a client dataset tag.
