G
Guest
hello,
using access 2003 and sql syntax, how would I accomplish the following:
I have 4 tables of which are not related, but i need to get data from all 4.
table 1 (contains all employees):
- userid
- fullname
table 2 (contains all employees):
- fullname
- dept#
- deptname
table 3 (contains only contractors):
- userid
- fullname
table 4:
- domainname
- username
What I need to do is produce the following results:
table4.domainuserid, fullname (the domainuserid from either table 1 or 3),
table2.dept# (if domainuserid is in table3 list "ctr", but if in table1 list
table1.dept#, otherwise nothing), table2.deptname (if domainuserid is in
table3 list "contractor", but if in table1 list table1.deptname, otherwise
nothing) We need all records in table4 (left join) but need to pull together
the other data from the other tables.
i have written the following sql statement but it doesn't returns all values
because the fullname in tables 2 and 3 are not the same. The last name and
the first name are correct, but the middle initial may not be or they had
other characters jr, sr, etc. But the fullname should always be at least
<lastname>,<firstname>.
SELECT [table4].Username AS [Dom UserID], [table1].UserID AS [Emp UserID],
IIf([table3].UserID,[table3].Name,[table1].Name) AS Name,
IIf([table3].Name,"CTR",[table2].[Dept#]) AS [Dept #],
IIf([table3].Name,"Contractors",[table2].[Dept name]) AS [Dept Name]
FROM ([table4] LEFT JOIN ([table1] LEFT JOIN [table2] ON
[table1].Name=[table2].Name) ON [table4].Username=[table1].UserID) LEFT JOIN
[table3] ON [table4].Username=[table3].UserID
ORDER BY IIf([table3].Name,"CTR",[table2].[Dept#]), [table4].Username;
There could be records in table4 that cannot be matched to table 1 or table
3, but I still need them listed. I need some way to join tables 4, 1, and 2
and 4, 1, 3. The only way to link the 4 tables is like this:
table4.username to table1.userid OR table3.userid
table1.fullname to table2.fullname <<<this is the problem since the
fullname is inconsistent. The only consistency is lastname,firstname
(Whitefield,Bill)>>>
How would I write the sql statement to get values I need?
Thank you in advance.
using access 2003 and sql syntax, how would I accomplish the following:
I have 4 tables of which are not related, but i need to get data from all 4.
table 1 (contains all employees):
- userid
- fullname
table 2 (contains all employees):
- fullname
- dept#
- deptname
table 3 (contains only contractors):
- userid
- fullname
table 4:
- domainname
- username
What I need to do is produce the following results:
table4.domainuserid, fullname (the domainuserid from either table 1 or 3),
table2.dept# (if domainuserid is in table3 list "ctr", but if in table1 list
table1.dept#, otherwise nothing), table2.deptname (if domainuserid is in
table3 list "contractor", but if in table1 list table1.deptname, otherwise
nothing) We need all records in table4 (left join) but need to pull together
the other data from the other tables.
i have written the following sql statement but it doesn't returns all values
because the fullname in tables 2 and 3 are not the same. The last name and
the first name are correct, but the middle initial may not be or they had
other characters jr, sr, etc. But the fullname should always be at least
<lastname>,<firstname>.
SELECT [table4].Username AS [Dom UserID], [table1].UserID AS [Emp UserID],
IIf([table3].UserID,[table3].Name,[table1].Name) AS Name,
IIf([table3].Name,"CTR",[table2].[Dept#]) AS [Dept #],
IIf([table3].Name,"Contractors",[table2].[Dept name]) AS [Dept Name]
FROM ([table4] LEFT JOIN ([table1] LEFT JOIN [table2] ON
[table1].Name=[table2].Name) ON [table4].Username=[table1].UserID) LEFT JOIN
[table3] ON [table4].Username=[table3].UserID
ORDER BY IIf([table3].Name,"CTR",[table2].[Dept#]), [table4].Username;
There could be records in table4 that cannot be matched to table 1 or table
3, but I still need them listed. I need some way to join tables 4, 1, and 2
and 4, 1, 3. The only way to link the 4 tables is like this:
table4.username to table1.userid OR table3.userid
table1.fullname to table2.fullname <<<this is the problem since the
fullname is inconsistent. The only consistency is lastname,firstname
(Whitefield,Bill)>>>
How would I write the sql statement to get values I need?
Thank you in advance.