# Fallback When Column Does Not Exist?

**URL:** <https://forum.inductiveautomation.com/t/fallback-when-column-does-not-exist/9406>\
**Category:** Ignition\
**Created:** [December 4, 2014, 7:31pm UTC](https://forum.inductiveautomation.com/t/fallback-when-column-does-not-exist/9406 "2014-12-04T19:31:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlteel](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@jlteel](https://forum.inductiveautomation.com/u/jlteel)\
**Post date:** [December 4, 2014, 7:31pm UTC](https://forum.inductiveautomation.com/t/fallback-when-column-does-not-exist/9406/1 "2014-12-04T19:31:31Z")

</div>

I’m binding several fields to SQL statements, and in the interest of code re-use would like to be able to use the same statement even when a particular column does not exist in the database. The fallback field works well for null values in a column. But what about when the column doesn’t even exist? Is there a way to handle situations like this?

Thanks!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 8, 2014, 12:18pm UTC](https://forum.inductiveautomation.com/t/fallback-when-column-does-not-exist/9406/2 "2014-12-08T12:18:23Z")

</div>

The best way would be to query the schema information and construct queries from there. But there is another, indirect way that works…  
Here is an excerpt from a table:

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/11cc308e16f08e39ee5731b8f348b1dc39ed4965.png)  

Here is a query that counts the number of rows that say “PASS” in data1 (An existing column):

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/98d75341d7e8b596a8677e5f9f9735442f5b41a2.png)  

And here is the same query but using data\_1 (A column that doesn’t exist)

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c6e432db7821d8a4cae0644585cb94dbf95c725f.png)  

How does it work?

If the colum exists, the query gets traslated as WHERE t.data1=‘pass’  
Otherwise, it gets translated as WHERE dummy.data1=1

Hope this helps!

---

<div class="post-metadata">

**Author:** ![jlteel](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@jlteel](https://forum.inductiveautomation.com/u/jlteel)\
**Post date:** [December 8, 2014, 3:33pm UTC](https://forum.inductiveautomation.com/t/fallback-when-column-does-not-exist/9406/3 "2014-12-08T15:33:33Z")

</div>

Thank you, Jordan. I’m not completely sure I understand this yet, so I’m going to have to stare at it for a little longer, but it may work in my situation.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 8, 2014, 4:14pm UTC](https://forum.inductiveautomation.com/t/fallback-when-column-does-not-exist/9406/4 "2014-12-08T16:14:58Z")

</div>

Yeah, doing sub-queries like this is not especially my forte. I just hit on this once upon a time and said “I ouhgta write that down”… It was one of those few times I actually wrote it down! 😆
