Can a Add a String to a Union Query?

R

ryguy7272

Is there an easy way to add a string to all rows in the last column of a
Union Query? Below is my SQL:
SELECT * FROM qryAdvBookingsNextQ;
UNION ALL SELECT * FROM qryAdvBookingsCurrentQ;

I want to add ‘Revenue’ to all rows in the last column without going back to
the original Select Query because the entire query process is quite
complicated and I would have to spend a significant amount of time reverse
engineering a large number of queries. I know it is very easy to do this in
a Select Query; I need to know if I can do something similar in a Union Query.

TIA!!
Ryan---
 
L

Lord Kelvan

SELECT *, "Revenue" as enterfieldtitlehere FROM qryAdvBookingsNextQ;
UNION ALL SELECT *, "Revenue" as enterfieldtitlehere FROM
qryAdvBookingsCurrentQ;

that puts it at the front of the line not the end though what you need
to do to put ti at the end is select each field seperatally and put
the , "Revenue" as enterfieldtitlehere at the end of the select list

hope this helps

regards
kelvan
 
J

Jeff Boyce

One way to look at this is that your "SELECT * ..." is going to return all
the fields from your query(ies).

So, why not add the new column/field into each of the underlying queries?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
R

ryguy7272

Thanks for the help today LK! Thanks for the help yesterday too!

Regards,
Ryan---
 
M

Marshall Barton

ryguy7272 said:
Is there an easy way to add a string to all rows in the last column of a
Union Query? Below is my SQL:
SELECT * FROM qryAdvBookingsNextQ;
UNION ALL SELECT * FROM qryAdvBookingsCurrentQ;

I want to add ‘Revenue’ to all rows in the last column without going back to
the original Select Query because the entire query process is quite
complicated and I would have to spend a significant amount of time reverse
engineering a large number of queries. I know it is very easy to do this in
a Select Query; I need to know if I can do something similar in a Union Query.


A UNION query is made up of two or more SELECT queries so
you can easily do that:

SELECT *, "Revenue" As XXX FROM qryAdvBookingsNextQ;
UNION ALL
SELECT *, "Revenue" FROM qryAdvBookingsCurrentQ
 

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

Top