Union Query problem

S

Simon

Can any ne see what is wrong with this union Query

SELECT tblorderProduct.[Quantity] AS Quantity,
tblorderProduct.[ProductID] AS IDNumber,
tblorderProduct.[TotalExVAT] AS Total,
tblorderProduct.[Date] AS Date,
'tblorderProduct' AS TheType

FROM tblorderProduct


UNION ALL SELECT tblorderProductsWS.[Quantity] AS Quantity,
tblorderProductsWS.[IDNumber] AS IDNumber,
tblorderProductsWS.[Date] AS Date,
tblorderProductsWS.[Total] AS Total,

'tblorderProductsWS' AS TheType
FROM tblorderProductsWS



Error Message
The SELECT dtatment includes a reserved word or an argument name that
is misspelled or missing or the ounction is incorrect


Thanks

Simon
 
B

Baz

"Date" is a reserved word, you can't use it as an alias.

Once you've fixed that, the next problem you will encounter is that you've
transposed the date and total columns between the two queries.
 
S

SteveM

'Date' is a reserved word in Access, in fact, it is actually an Access
function that returns the current days date. It shouldn't be a column name in
your table, Use OrderDate or something as descriptive.

You don't need to use the 'AS' to create an alias for the column if the name
of the column is ok. For example, you don't need to alias Quantity AS
Quantity - it will already return with that name.

Also, the field order/names one each side of your Union must match - you
have Total and Date in different order...

These lines bothers me:
'tblorderProduct' AS TheType
'tblorderProductsWS' AS TheType
What are they supposed to represent?

Steve



Simon said:
Can any ne see what is wrong with this union Query

SELECT tblorderProduct.[Quantity] AS Quantity,
tblorderProduct.[ProductID] AS IDNumber,
tblorderProduct.[TotalExVAT] AS Total,
tblorderProduct.[Date] AS Date,
'tblorderProduct' AS TheType

FROM tblorderProduct


UNION ALL SELECT tblorderProductsWS.[Quantity] AS Quantity,
tblorderProductsWS.[IDNumber] AS IDNumber,
tblorderProductsWS.[Date] AS Date,
tblorderProductsWS.[Total] AS Total,

'tblorderProductsWS' AS TheType
FROM tblorderProductsWS



Error Message
The SELECT dtatment includes a reserved word or an argument name that
is misspelled or missing or the ounction is incorrect


Thanks

Simon
 
D

Douglas J. Steele

That's a pretty common approach to ensure you know from which table details
in the Union statement originated.
 
S

SteveM

Gotcha but the identifier used may make sense to the developer but not users...
If there are a lot of records being returned, it would be more efficient to
use a simpler identifier (less characters) or even a digit...unless this
value is being used as a parameter somewhere else.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Adding data to Subform and save and running a total price calc 0
Union Qury 1
Insert into code 1
Union Query 2
Union Querys 1
union qerys 3
Running Yearly Sum 1
Code help 3

Top