Try:
UPDATE UniqueSups
SET ssn =
(SELECT DISTINCT N.ssn
FROM tblNonNormalized AS N
WHERE N.supervisorname = UniqueSups.name
AND N.ssn IS NOT NULL)
This can only work if you have a single SSN for each unique name in
your non-normalized table. Otherwise you'll get an error and you'll
have to do some more data cleansing.

Signature
David Portas
SQL Server MVP
--
> I need to bring the ssn's into UniqueSups (supervisors) from
> tblNonNormalized. My inherited DB is not normalized and I find it
[quoted text clipped - 12 lines]
> TIA
> Moe
Huh? Post your table structure. field names? types? meanings?
union queries are about as hard as falling down. The *only* trick is
that you need union-compatible fields (generally of the same type).
Say you have two tables, tblA and tblB, with structures like this:
CREATE TABLE tblA(
SSN Text(9) PRIMARY KEY,
Firstname Text(20),
Lastname Text(25),
...
)
and
CREATE TABLE tblB(
SocSecNo Text(9) PRIMARY KEY,
FName Text(20),
LName Text(25),
...
)
Union is no big deal - you just have to alias the fields in one table
so they map right...
SELECT SSN, FirstName, LastName
FROM tblA
UNION ALL
SELECT SocSecNo as SSN, FName as FirstName, LName as LastName
FROM tblB
ORDER BY SSN;
(aliasing is the [FieldName] AS (alias) stuff.
IF the database really is not normalized, you *may* need to normalize
it to get it to work... so you might want to post the relevant parts of
the database structure and what you need to do with the data. Whether
you normalize will depend on several factors, and without knowing some
more about the thing, it's hard to tell what to advise. Could be a
huge undertaking for very little payoff... but then it might be worth
it or relatively painless...
mo - 28 Feb 2005 16:03 GMT
Further clarification:
I am seeking to normalize the data.
tblNonNormalized: (Employees and supervisors)
Name SSN Supervisor
Jon 222 Ed
Sam 333 Ed
Ed 444 Tom
destination: UniqueSups (created from Create Table Distinct
SupervisorName)
Ed 444
Tom 555
They've (read: previous idiot designer) placed children and parents in
the same table! I am trying to extract the unique supervisors into a
new table. My new table would contain supervisorname Ed and his SSN
just once rather than one for every person he supervises. The plain
old falling off a log update query is not working, as it is copying all
the ssns rather than just those where it is a supervisor record.
(Sorry to obfuscate, I was trying to simplify the problem.) The
suggested query from David Portas, thank you btw, does not work in
Access "requires [UPDATE], [DELETE] etc."
It does not work in SQL Server because "Subquery returned more than 1
value. This is not permitted when the subquery follows =, !=, <, <= ,
>, >= or when the subquery is used as an expression.
The statement has been terminated." This syntax does work on other
normaized tables that I created.
UPDATE UniqueSups
SET ssn =
(SELECT DISTINCT N.ssn
FROM tblNonNormalized AS N
WHERE N.supervisorname = UniqueSups.name
AND N.ssn IS NOT NULL)
> > I need to bring the ssn's into UniqueSups (supervisors) from
> > tblNonNormalized. My inherited DB is not normalized and I find it
[quoted text clipped - 55 lines]
> huge undertaking for very little payoff... but then it might be worth
> it or relatively painless...
David Portas - 28 Feb 2005 16:58 GMT
> It does not work in SQL Server because "Subquery returned more than 1
> value. This is not permitted when the subquery follows =, !=, <, <= ,
>, >= or when the subquery is used as an expression.
That's because you have more than one matching SSN for a given name in
tblNonNormalized. In other words you need to clean up your data first.
Try this query:
SELECT *
FROM tblNonNormalized
WHERE supervisorname IN
(SELECT supervisorname
FROM tblNonNormalized
GROUP BY supervisorname
HAVING MIN(ssn)<MAX(ssn))
Then decide what you want to do about the duplicate names with
different SSNs. If you need more help, please post again with CREATE
TABLE statements for your tables and a few rows of sample data as
INSERT statements so that we can reproduce your problem.

Signature
David Portas
SQL Server MVP
--
mo - 28 Feb 2005 20:41 GMT
Thank you very much David, cleaning the data is the goal.
This query actually succeeds in updating the appropriate SSNs in SQL
Server, but it doesn't work in Access, where I'm tasked to work. In
Access 2002, I'm still getting the 'must be an updateable query' even
though tblNonNormal is an attached SQL server table and the one I'm
writing to is a local Access one.
UPDATE UniqueSupervisors
SET UniqueSupervisors.SSN =
(Select Distinct [tblNonNormal].[SSN]
FROM tblNonNormal
WHERE UniqueSupervisors.SupervisorEmail = tblNonNormal.Email)
Any thoughts why it won't run? tia Moe
> > It does not work in SQL Server because "Subquery returned more than 1
>
[quoted text clipped - 18 lines]
> TABLE statements for your tables and a few rows of sample data as
> INSERT statements so that we can reproduce your problem.
David Portas - 28 Feb 2005 21:37 GMT
This is a SQL Server group . You'll probably get better help in an
Access group. Alternatively, run it as a pass-though query.

Signature
David Portas
SQL Server MVP
--