# dbQuery check for null results

**URL:** <https://community.cdata.com/t/dbquery-check-for-null-results/1190>\
**Category:** CData Arc\
**Tags:** question, dbquery, null-check, arcscript\
**Created:** [September 15, 2025, 3:55pm UTC](https://community.cdata.com/t/dbquery-check-for-null-results/1190 "2025-09-15T15:55:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Travis](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@Travis](https://community.cdata.com/u/Travis)\
**Post date:** [September 15, 2025, 3:56pm UTC](https://community.cdata.com/t/dbquery-check-for-null-results/1190/1 "2025-09-15T15:56:56Z")

</div>

Is there a better way to check for null results from a dbQuery, I feel dirty for coming up with this:

```xml
<arc:set attr="db.query">select null as something;</arc:set><arc:call op="dbQuery" in="db" out="results"> <arc:if exp="'[results.*]' == '<table></table>'"> <!-- handle null --> </arc:if> ...</arc:call>

```

---

<div class="post-metadata">

**Author:** ![TR3X](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@TR3X](https://community.cdata.com/u/TR3X)\
**Post date:** [September 16, 2025, 9:28am UTC](https://community.cdata.com/t/dbquery-check-for-null-results/1190/2 "2025-09-16T09:28:59Z")

</div>

Hi Travis,

I have reviewed your query, and I understand why you added ‘select null as something’ as a check to handle empty results. However, I wanted to provide you with&nbsp;a bit more context. Let me explain a working example script with you.

```auto
<arc:set attr="db.driver" value="System.Data.CData.MySql" /><arc:set attr="db.conn" value="Server=localhost;Database=new;UID= ****;Password=**** ;"/><arc:set attr="db.query" value="SELECT * FROM `test`"/><arc:set attr="output.data"><Items><arc:call op="dbQuery" item="db"><test><arc:enum item="db"><arc:if exp="[_attr | startswith('db:')]"><[_attr | split(:,2)]>[_value]</[_attr | split(:,2)]></arc:if></arc:enum><arc:else><arc:throw code="myerror" desc="null Value" /></arc:else></test></arc:call></Items></arc:set><arc:set attr="output.filename" value="test.txt" /><arc:push item="output" />

```

```auto
 

```

**What this script does**

- It sets up a database connection (MySQL in this case).
- Runs the query **SELECT \* FROM ‘test’**.
- Iterates through the results ( **arc:enum item=”db”** ) and outputs each row/column.
- If no data is returned, the **arc:else** branch is triggered and throws a custom error ( **null Value** ). You can modify the error description in this line according to your needs: **\<arc:throw code=“myerror” desc=“null Value” /\>**

So, in effect, you don’t need to rely on comparing the raw **\<table\>\</table\>** &nbsp;output — this script gracefully handles the case where no records are returned by explicitly checking and throwing an error if the result is null/empty.

If scripting is the only option in your current use case, this solution works fine. But for cleaner handling and long-term maintainability, we recommend using a **dedicated database connector** (like the MySQL connector). Connectors usually provide built-in ways to handle empty result sets or errors, so you won’t need to manually check for&nbsp; **\<table\>\</table\>** &nbsp;or add workarounds.

I hope this helps you achieve your use case. Please feel free to reach out to us at **[arcsupport@cdata.com](mailto:arcsupport@cdata.com)** if you have any further questions.
