# Adding Union changes field names

**URL:** <https://forum.xojo.com/t/adding-union-changes-field-names/14107>\
**Category:** Databases\
**Created:** [February 5, 2014, 7:04pm UTC](https://forum.xojo.com/t/adding-union-changes-field-names/14107 "2014-02-05T19:04:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dean\_Davidge](https://forum.xojo.com/user_avatar/forum.xojo.com/dean_davidge/32/244_2.png) [@Dean\_Davidge](https://forum.xojo.com/u/Dean_Davidge)\
**Post date:** [February 5, 2014, 7:04pm UTC](https://forum.xojo.com/t/adding-union-changes-field-names/14107/1 "2014-02-05T19:04:43Z")

</div>

[quote] sql = “SELECT A.MeterNo, A.DateTime, A.MoreVals, A.ReadingID, B.\* FROM Readings A, ExtReadings B WHERE A.MoreVals = B.ExtendedID AND “+\_  
“A.MeterNo = " + Units.RowTag(i) + " AND A.DateTime \< '” + d1+”’ AND A.DateTime \> '” + d2 + “’ AND A.MoreVals \> 0 UNION SELECT A.MeterNo, M” +\_  
minmax + “(A.DateTime), A.MoreVals, A.ReadingID, B.\* FROM Readings A, ExtReadings B WHERE A.MoreVals = B.ExtendedID AND “+\_  
“A.MeterNo = " + Units.RowTag(i) + " AND A.DateTime \>= '” + d3+”’ AND A.DateTime \<= '” + d4 +\_  
“’ AND A.MoreVals \> 0 ORDER BY A.ReadingID DESC”[/quote]  
Originally this query ended before the UNION and everything worked fine. When I looked at the recordset contents in the debugger, the first field was named  
“MeterNo”. Since adding the UNION, the first field and the rest of the fields from the Readings table are all “A.MeterNo”, “A.DateTime”, etc. This would not be a problem except that the code that follows uses either the results of this query or another query on a single table so I cannot make it return a field name starting with “A.” The first time the code encounters something like `thisOne = rs.field("MeterNo").StringValue` it throws an exception since the field is now “A.MeterNo”. Is there a way to handle this short of duplicating most of my report code?

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [February 5, 2014, 7:41pm UTC](https://forum.xojo.com/t/adding-union-changes-field-names/14107/2 "2014-02-05T19:41:20Z")

</div>

Make sure they have the name you WANT deliberately rather than just by coincidence

```auto
SELECT A.MeterNo as MeterNo, A.DateTime as DateTime, A.MoreVals as MoreVals  etc .
UNION 
SELECT A.MeterNo as MeterNo, . etc ..
```

---

<div class="post-metadata">

**Author:** ![Dean\_Davidge](https://forum.xojo.com/user_avatar/forum.xojo.com/dean_davidge/32/244_2.png) [@Dean\_Davidge](https://forum.xojo.com/u/Dean_Davidge)\
**Post date:** [February 5, 2014, 8:19pm UTC](https://forum.xojo.com/t/adding-union-changes-field-names/14107/3 "2014-02-05T20:19:42Z")

</div>

Thanks Norman. Works great.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:04pm UTC](https://forum.xojo.com/t/adding-union-changes-field-names/14107/4 "2020-10-29T17:04:02Z")

</div>


