Creating a Linking Column from table to the other

  • How can i create the employee code column from Staff List into Revenue table?


    You must be logged in to view attached files.
  • 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

    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

    The Scary DBA
    Author of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd Edition
    Product Evangelist for Red Gate Software

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply