I am trying to figure out how to create a query/tsql that can import values from csv file to existing table. This is example how few records of csv looks like:
LastName, FirstName, Supervisor
Michael, Scott, John Smith
Joe, Martin, Michael Scott
And my existing table in SQL Employee table All columns already have values except SupervisorId (supervisorId is a foreign key that points at main key of the same table - EmployeeId)
What I want to achieve is to write a script that will take Supervisor name from csv file, search employee table for row with given supervisor name (first name + last name), take his EmployeeId and insert it into his subordinate SupervisorId column.
Is it possible to create such script? So far I have found only simple queries like:
BULK INSERT Employee
FROM 'D:\Employees.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
TABLOCK
)
But it is not even close to what I want to achieve