# Need to return 0 when ther is not any data

**URL:** <https://forum.inductiveautomation.com/t/need-to-return-0-when-ther-is-not-any-data/15232>\
**Category:** Ignition\
**Created:** [September 1, 2017, 8:10pm UTC](https://forum.inductiveautomation.com/t/need-to-return-0-when-ther-is-not-any-data/15232 "2017-09-01T20:10:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brocha](https://avatars.discourse-cdn.com/v4/letter/b/dfb087/32.png) [@brocha](https://forum.inductiveautomation.com/u/brocha)\
**Post date:** [September 1, 2017, 8:10pm UTC](https://forum.inductiveautomation.com/t/need-to-return-0-when-ther-is-not-any-data/15232/1 "2017-09-01T20:10:18Z")

</div>

I am using system.db.runPrepQuery for a Select statement, but when there is not any information I need to return a 0. If i was doing this in a SQL Query I would use Select coalesce( Select \* From Here Where a=b),0). The issue is when I am trying to do this same function in the scripting function of a button with runPrepQuery. Any help with the scripting would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 1, 2017, 8:43pm UTC](https://forum.inductiveautomation.com/t/need-to-return-0-when-ther-is-not-any-data/15232/2 "2017-09-01T20:43:25Z")

</div>

you can check the length of a dataset in scripting using a runPrepQuery

```auto
a = 'b'
myDS = system.db.runPrepQuery("SELECT ID, EDate, ETitle, EText FROM ETable WHERE(ETitle = ?)", [a],'DataSourceName')
print len(myDS)
If len(myDS)>0:
     DoSomething
else:
     DoSomethingElse

```

---

<div class="post-metadata">

**Author:** ![brocha](https://avatars.discourse-cdn.com/v4/letter/b/dfb087/32.png) [@brocha](https://forum.inductiveautomation.com/u/brocha)\
**Post date:** [September 1, 2017, 9:06pm UTC](https://forum.inductiveautomation.com/t/need-to-return-0-when-ther-is-not-any-data/15232/3 "2017-09-01T21:06:52Z")

</div>

Thanks for the help. Did not think about length to check against. Worked great.
