Update Query Question

R

randlesc

I know this is a very basic question but I honestly don't know where to find
the information specific to this question.

I have a table of employees names and their immunizations. The immunization
information comes from Query 1 of another database which is updated each
week. I have been deleting the contents of the table and replacing it with
the contents of Query 1 each week; the big problem is some employees don't
have their immunization information in the Query 1 it comes from yet another
database and I re-fill in those blanks each week and others are marked N/A.

I would like to construct an update query that will take the "Yes" from
Query 1 and put into the immunization column of table 1 only if that space in
table 1 is N or contains N/A.

Obviously I've never made an update query before and in fact I'd forgotten
about them until this weekend when I was thinking--there has to be an easier
way.

How do I set this up?

TABLE 1:

Employee ID, Employee Name, Department, Immunization (y/n/NA

QUERY 1
Employee ID, Employee Name, Immunization

Thanks
 
R

randlesc

Thank you. Sorry for the delay, I must have forgotten to check "notify me of
replies."

This looks great. My only question is, there is some data in immunization
that doesn't come from the second query--these are people, about 100, whose
information comes from a variety of systems across the company, mostly legacy
systems--if I've entered this into the main table will these be overwritten
when I run the query because they won't match with what the Query 1 will
return (query 1 will return them as blanks, most times).

Thanks again. I can't wait to try this out.

KenSheridan via AccessMonster.com said:
I'd do this in three stages:

1. Append new employees form Query 1 to Table 1.

2. Update the Employee Name column in Table 1 unconditionally from Query 1.
Any whose values have changes will be changed to the new values, any who have
not changed will simply be updated to what they were already, so in effect
won't be changed. I note that Query 1 does not have a Department column, so
these will remain unchanged in Table 1.

3. Update the Immunization column in Table 1 from Query 1 only where the
Query 1 Immunization values are 'Y' and Table 1 contains values other than
'Y' or is Null.

So you'd need one 'append' and two simple 'update' queries for this, which
you'd execute in sequence:

First, to insert new employees, if any:

INSERT INTO [Table 1] ([Employee ID], [Employee Name], [Immunization])
SELECT [Employee ID], [Employee Name], [Immunization]
FROM [Query 1]
WHERE NOT EXISTS
(SELECT *
FROM [Table 1]
WHERE [Table 1].[Employee ID] = [Query 1].[Employee ID]);

To update employee names:

UPDATE [Table 1] INNER JOIN [Query 1]
ON [Table 1].[Employee ID] = [Query 1].[Employee ID]
SET [Table 1].[Employee Name] = [Query 1].[Employee Name];

To update the immunization column:

UPDATE [Table 1] INNER JOIN [Query 1]
ON [Table 1].[Employee ID] = [Query 1].[Employee ID]
SET [Table 1].[Immunization] = [Query 1].[Immunization]
WHERE [Query 1].[Immunization] = "Y"
AND ([Table 1].[Immunization] <> "Y"
OR [Table 1].[Immunization] IS NULL);

Note that in the last query the positions of the parentheses are important to
force the OR operation to evaluate independently of the AND operation in the
WHERE clause.

All of the above assumes that the Employee ID values do not change of course
as these are used to join the query and table. Assuming that to be the case
you could automate the whole operation by executing the three queries in
sequence with a single click of a button on an unbound dialogue form.

Ken Sheridan
Stafford, England
I know this is a very basic question but I honestly don't know where to find
the information specific to this question.

I have a table of employees names and their immunizations. The immunization
information comes from Query 1 of another database which is updated each
week. I have been deleting the contents of the table and replacing it with
the contents of Query 1 each week; the big problem is some employees don't
have their immunization information in the Query 1 it comes from yet another
database and I re-fill in those blanks each week and others are marked N/A.

I would like to construct an update query that will take the "Yes" from
Query 1 and put into the immunization column of table 1 only if that space in
table 1 is N or contains N/A.

Obviously I've never made an update query before and in fact I'd forgotten
about them until this weekend when I was thinking--there has to be an easier
way.

How do I set this up?

TABLE 1:

Employee ID, Employee Name, Department, Immunization (y/n/NA

QUERY 1
Employee ID, Employee Name, Immunization

Thanks

--
Message posted via AccessMonster.com


.
 

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