# Querying HubDB in Programmable Email Content

**URL:** <https://community.hubspot.com/t/querying-hubdb-in-programmable-email-content/111857>\
**Category:** APIs & Integrations\
**Tags:** email, developer-tools, professional\
**Created:** [July 12, 2024, 4:08pm UTC](https://community.hubspot.com/t/querying-hubdb-in-programmable-email-content/111857 "2024-07-12T16:08:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ah8](https://avatars.discourse-cdn.com/v4/letter/a/ac91a4/32.png) [@ah8](https://community.hubspot.com/u/ah8)\
**Post date:** [July 12, 2024, 4:08pm UTC](https://community.hubspot.com/t/querying-hubdb-in-programmable-email-content/111857/1 "2024-07-12T16:08:11Z")

</div>

Hi,

I am trying to figure out why the query I am making isn’t working.

The output shows:

Debug Info:

Professions: ChiropracticDoctor

States: AK

Renewal Date:

All rows in HubDB Table: (Fills in properly)

Query: profession=ChiropracticDoctor&state=AK

Number of rows retrieved for ChiropracticDoctor in AK: 0

No matching data found for the given criteria.  
This is the code I am using for it:

```lia-code-sample
<style>
 body {
 font-family: Arial, sans-serif;
 color: #1e3e4e;
 }
 p {
 font-family: Arial, sans-serif;
 color: #1e3e4e;
 margin: 0 0 10px 0;
 }
 .content-block {
 padding: 30px;
 }
</style>

{% set professions = deal.customer_credential_designation_profession_query_parameter|split(',') %}
{% set states = deal.customer_credential_state_licensure_state|split(',') %}
{% set renewal_date = deal.renewal_date %}

<!-- Debug: Display input values -->
<div class="content-block">
 <p>Debug Info:</p>
 <p>Professions: {% for profession in professions %}{{ profession }}{% if not loop.last %}, {% endif %}{% endfor %}</p>
 <p>States: {% for state in states %}{{ state }}{% if not loop.last %}, {% endif %}{% endfor %}</p>
 <p>Renewal Date: {{ renewal_date }}</p>
</div>

<!-- Display all rows in HubDB table for debugging -->
{% set all_hubdb_rows = hubdb_table_rows(21114150) %}
<div class="content-block">
 <p>All rows in HubDB Table:</p>
 {% for row in all_hubdb_rows %}
 <p>Profession: {{ row.profession }}, State: {{ row.state }}, Email Content: {{ row.email_content }}</p>
 {% endfor %}
</div>

<!-- Stage 1: Query HubDB -->
{% if professions and states %}
 {% set content_found = false %}
 {% for profession in professions %}
 {% for state in states %}
 {% set query = "profession=" ~ profession|trim ~ "&state=" ~ state|trim %}

 <!-- Debug: Display constructed query -->
 <div class="content-block">
 <p>Query: {{ query }}</p>
 </div>

 {% set hubdb_rows = hubdb_table_rows(21114150, query) %}

 <!-- Debug: Check if rows are retrieved -->
 <div class="content-block">
 <p>Number of rows retrieved for {{ profession }} in {{ state }}: {{ hubdb_rows|length }}</p>
 </div>

 <!-- Stage 2: Render the Email Content -->
 {% if hubdb_rows|length > 0 %}
 {% set content_found = true %}
 {% for row in hubdb_rows %}
 <div class="content-block">
 <p>
 <strong>Profession:</strong> {{ profession }} <br>
 <strong>State:</strong> {{ state }}
 </p>
 <p>
 <span>{{ row.email_content }}</span>
 </p>
 </div>
 {% endfor %}
 {% endif %}
 {% endfor %}
 {% endfor %}
 {% if not content_found %}
 <div class="content-block">
 <p>No matching data found for the given criteria.</p>
 </div>
 {% endif %}
{% else %}
 <div class="content-block">
 <p>Required deal properties are missing or invalid.</p>
 </div>
{% endif %}

```

Is my query just not formatted properly?  
Thank you

---

<div class="post-metadata">

**Author:** ![SteveHTM](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stevehtm/32/22074_2.png) [@SteveHTM](https://community.hubspot.com/u/SteveHTM)\
**Post date:** [July 13, 2024, 4:17pm UTC](https://community.hubspot.com/t/querying-hubdb-in-programmable-email-content/111857/2 "2024-07-13T16:17:44Z")

</div>

@ah8 - in your ‘hubdb\_table\_rows’ function call, have you established the filter ‘query’ with the best format? I think the documentation here could do with a few better examples: [CMS API | HubDB - HubSpot docs](https://developers.hubspot.com/beta-docs/guides/api/cms/hubdb#filter-returned-rows)

but the basic setup for an filter string is:

columnName\_\_operator

and for TEXT columns, use `__icontains` for a case-insensitive match, or just `profession=ChiropracticDoctor` (no operator suffix) for an exact match, `__contains` is only valid for MULTISELECT columns. than eq, so I think your query string might work better if it was set up like:

`{% set query = "profession __contains=" ~ profession|trim ~ "&state__ contains=" ~ state|trim %}`

Hope this is helpful,

Steve

_Moderator Note: this post was reviewed for relevancy and optimized for clarity on September 30, 2026. Thank you for your contributions to the HubSpot Community!_
