Union query missing various column data (1 Viewer)

Trocergian

Registered User.
Local time
Today, 17:36
Joined
Apr 6, 2009
Messages
16
I am running a union query on two queries.
Both queries have the exact same columns, both run perfectly well separately, showing all expected data.
When running as a union:
ELECT qry_POS_X_CurrentPO.* FROM qry_POS_X_CurrentPO
UNION ALL
SELECT qry_POS_X_E1_OrderQty_X.* FROM qry_POS_X_E1_OrderQty_X;
Some of the columns from the first listed query are missing data.
Out of 19 records, 11 are missing data.
From those the data is missing from 8 out of 21 coloumns.
I'm at a loss to figuring out the cause and open to any suggestions.
 

tvanstiphout

Active member
Local time
Today, 15:36
Joined
Jan 22, 2016
Messages
222
Can you isolate this issue into a new database, with only the relevant tables and queries, and some test data that demonstrates the problem?
 

plog

Banishment Pending
Local time
Today, 17:36
Joined
May 11, 2011
Messages
11,646
Don't use the *, explicitly state each field and build it 1 field at a time:

Code:
SELECT Field1 FROM Query1
UNION ALL
SELECT Field1 FROM Query2

Then when that works:

Code:
SELECT Field1, Field2 FROM Query1
UNION ALL
SELECT Field1, Field2 FROM Query2

Then


Code:
SELECT Field1, Field2, Field3 FROM Query1
UNION ALL
SELECT Field1, Field2, Field3 FROM Query2

etc.etc.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:36
Joined
May 7, 2009
Messages
19,245
agree with post#3, your Union query should have Same Column Position and Same number of columns.
otherwise the result is unpredictable.
 

Trocergian

Registered User.
Local time
Today, 17:36
Joined
Apr 6, 2009
Messages
16
Update...
Per Plog's suggesting I started adding column by colum and quickly noticed the problem was isolated to one particular table in the query.
Then per tvanstiphout's suggestion I rebuilt that table just using the needed column and sure enough the union ran fine.
I then created a new table in SQL server and replaced the problem one and things seem to be working perfectly.
Thanks for the help!
We recently changed changed computer so I'm gussing something happened to that talbe during the backup/restore process. An odd little bug to be sure as there seemed to be no issues elsewhere and that is an often used table, just with the union query. Odd, that.
 

Users who are viewing this thread

Top Bottom