I am trying to update a table based on the CSV file. I have got list of Id's and trim number in CSV and I need to update the Trim number based on the specific id's in the SQL table.
So far the script I have written
-- Create a temporary table for the import
drop table #InterpreterTrimNumbers
CREATE TABLE #InterpreterTrimNumbers(
[SAPInterpreterId] int,
TempTrimNumber varchar(100)
)
BEGIN TRANSACTION
-- Bulk import into the temporary table
BULK INSERT #InterpreterTrimNumbers FROM 'C:\CSVData\Trim numbers.csv' WITH (
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
ERRORFILE = 'C:\CSVData\Trim numbers-errors.csv',
TABLOCK
)
update Interpreters set TrimNumber = (select TempTrimNumber from #InterpreterTrimNumbers where #InterpreterTrimNumbers.SAPInterpreterId = Interpreters.SAPInterpreterID )
Commit Transaction
This one returns 1824 rows affected even thought the CSV file has only got 110 records. I only want to update the record with specific SAPInterpreterID
Any help is appreciated.