Parameter in Union Query

  • Thread starter Thread starter Jill
  • Start date Start date
J

Jill

I inherited about ten databases, Year2001, Year2002, etc. These databases are
not related, even though they have information about same ID's (For example,
ID 12224 is David Monk in Year2001, Year2002, etc.) Then I often see needs to
compare Year2001 and Year2002, etc. So I built another database, which is a
collection of an essential table from each year. There I created a union
query, which allows me to see a history of, say, David Monk. Problem is, when
I want to see a history of Judy Tyler, I have to type her ID ten times in
SQL. If there is a way I can create a parameter where I put an ID only once,
it would be splendid. Help?
Thank you.
 
Try the following

Parameter [Enter Name] Text(255);
SELECT *
FROM Year2001
WHERE [TheName] like [Enter Name] & "*"
UNION ALL
SELECT *
FROM Year2002
WHERE [TheName] like [Enter Name] & "*"
UNION ALL
SELECT *
FROM Year2003
WHERE [TheName] like [Enter Name] & "*"


Or use a saved UNION query as the source for another query
SELECT *
FROM Year2001
UNION ALL
SELECT *
FROM Year2002
UNION ALL
SELECT *
FROM Year2003

And then
SELECT *
FROM theSavedUnionQuery
WHERE [TheName] like [Enter Name] & "*"


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 

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


Back
Top