September 23, 2021 at 11:50 am
I'm looking at what you have shown here, but I don't see any other association between the two data sets except for the first name, SaleAgent in the Revenue data set, Employee Name in the Staff data set. So, however bad that is for a foreign key, and it's bad, that's your path. So, something like this:
SELECT [Employee Code]
FROM staff_list AS sl
JOIN revenue_extract AS re
ON sl.[EmployeeName] = re.SaleAgent
WHERE...;
That will do it based on what you have, but ooof. That's not a good way to run a railroad. See, the first name could easily be duplicated. I know a couple of Khalils and several Priyas. As soon as more than one Suzy walks through the door, your system is broken. You need to either be using both names in the Revenue data, which will help, but won't solve the problem, or, you need to get the Employee Code in there. If that's what you're trying to do, then right now, that first name join is your only hope, but you may run into issues. Maybe having:
...AND sl.Department = 'Customer Care'...
May help.
Good luck.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply