# Select query

**URL:** <https://forum.inductiveautomation.com/t/select-query/4839>\
**Category:** Ignition\
**Created:** [July 18, 2012, 5:56pm UTC](https://forum.inductiveautomation.com/t/select-query/4839 "2012-07-18T17:56:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [July 18, 2012, 5:56pm UTC](https://forum.inductiveautomation.com/t/select-query/4839/1 "2012-07-18T17:56:56Z")

</div>

Does this look like a good way to restrict multiple instances of a value (store) from appearing in my table.  
This is from my table binding script.  
This is the line in question

if system.db.runSelectQuery(“SELECT store FROM shipping\_stores”, ‘Sample’) like valueMod:  
#idNumber = system.db.runScalarQuery(“SELECT MAX(store) + 1 FROM shipping\_stores”)  
system.db.runUpdateQuery(“INSERT INTO shipping\_stores (store) VALUES (’%s’)” % (valueMod), ‘Sample’)  
else:   
system.db.runUpdateQuery(“UPDATE shipping\_stores SET groupname = ‘%s’ WHERE store = ‘%s’”% (value1, valueMod), ‘Sample’)  
system.db.runUpdateQuery(“UPDATE shipping\_stores SET modename = ‘%s’ WHERE store = ‘%s’”% (value2, valueMod), ‘Sample’)

EDIT:  
Solved.  
Used prepupdate query

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [July 18, 2012, 6:20pm UTC](https://forum.inductiveautomation.com/t/select-query/4839/2 "2012-07-18T18:20:16Z")

</div>

results = system.db.runPrepQuery(“SELECT \* FROM shipping\_stores WHERE store LIKE ?”, [valueMod], ‘Sample’)  
if results\< 1:  
#idNumber = system.db.runScalarQuery(“SELECT MAX(store) + 1 FROM shipping\_stores”)  
system.db.runUpdateQuery(“INSERT INTO shipping\_stores (store) VALUES (’%s’)” % (valueMod), ‘Sample’)  
system.db.runUpdateQuery(“UPDATE shipping\_stores SET groupname = ‘%s’ WHERE store = ‘%s’”% (value1, valueMod), ‘Sample’)  
system.db.runUpdateQuery(“UPDATE shipping\_stores SET modename = ‘%s’ WHERE store = ‘%s’”% (value2, valueMod), ‘Sample’)

This is what I came up with but I want to say if there isn’t anything in the dataset (results) then insert…  
I cant seem to use an appropriate not statement.  
Any ideas?

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [July 18, 2012, 6:39pm UTC](https://forum.inductiveautomation.com/t/select-query/4839/3 "2012-07-18T18:39:20Z")

</div>

Calling len() on the dataset will return how many rows are in the dataset. If your select statement was called on an empty table, then the dataset would have zero rows. The condition check for “if there’s nothing in the dataset” would be:

```auto
if len(results) == 0:
```

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [July 18, 2012, 6:51pm UTC](https://forum.inductiveautomation.com/t/select-query/4839/4 "2012-07-18T18:51:52Z")

</div>

thanks
