union qerys

S

Simon

can any one see whats wrong this this union query or tell me what could
be wrong

SELECT qryLedgerInvoicesWS.[InvoiceNumber] AS Number,
qryLedgerInvoicesWS.[InvoiceDate] AS Date,
qryLedgerInvoicesWS.[Total] AS Debit,
'qryLedgerInvoicesWS' AS TheType
FROM qryLedgerInvoicesWS

UNION ALL SELECT qryLedgerPaymentsWS.[InvoiceNumber] AS Number,
qryLedgerPaymentsWS.[Date] AS Date,
qryLedgerPaymentsWS.[Amount] AS Debit,
'qryLedgerPaymentsWS' AS TheType
FROM qryLedgerPaymentsWS

ORDER BY Date;
 
S

Smartin

Simon said:
can any one see whats wrong this this union query or tell me what could
be wrong

SELECT qryLedgerInvoicesWS.[InvoiceNumber] AS Number,
qryLedgerInvoicesWS.[InvoiceDate] AS Date,
qryLedgerInvoicesWS.[Total] AS Debit,
'qryLedgerInvoicesWS' AS TheType
FROM qryLedgerInvoicesWS

UNION ALL SELECT qryLedgerPaymentsWS.[InvoiceNumber] AS Number,
qryLedgerPaymentsWS.[Date] AS Date,
qryLedgerPaymentsWS.[Amount] AS Debit,
'qryLedgerPaymentsWS' AS TheType
FROM qryLedgerPaymentsWS

ORDER BY Date;

Would you tell us what is wrong with it? I.e., what does it do or not do
apart from your expectations?

One thing I would change... "Number" and "Date" are reserved words.
Reserved, that is, for Access. Best not to use those labels.
 
L

Larry Linson

Please clarify: what problem are you encountering?

Today just isn't a good day for me to play guessing games.

Just one comment... "Date" is a reserved word and not a good choice for a
Field Name or an Alias. I believe "Number" is also a reserved word, but less
likely to be troublesome than "Date" which is a built-in function returning
today's date and likely to be misinterpreted by Access.

Larry Linson
Microsoft Access MVP
 
V

Van T. Dinh

The problem is that both DATE and NUMBER are reserved words (synonym to
DATETIME and FLOAT respectively).

Use different Aliases or if you still want to use DATE and NUMBER (***not***
recommended), use square brackets in all instances like:

AS [NUMBER]

AS [DATE]

BTW, you don't need Aliases in the second part of the Union ... They are
simply ignored (but can give errors) so don't use them.
 

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

Union Query problem 5
Union Qury 1
Union Query 2
Union Querys 1
Union Query 4
Union Query 2
Union Queries - Column Headers 3
No Duplication or Data Suppression 3

Top