Fallback When Column Does Not Exist?

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!

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:


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


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


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!

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.

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! :laughing: