T-SQL update table A with values from table B (hard coded)

AMber 1 Reputation point
2022-08-23T07:55:19.137+00:00

I have table A where I have 164 distinct values for column code as Fellows:
May-Update-DTO terminated breaking One-two-One 'None"

etc

I also have a CSV file where all of these codes above are mapped to a different values that our software understands:

May-Update-DTO --> None Shift Terminated --> Value Time Breaking --> None Dom One-Two-One --> POE Exec "None" --> Manual

I have to essentially source this CSV file and update table A per the CSV values above. I can potentially load these CSV files into a local table. What would be the best way to accomplish this? CSV file has like 250 records.

Thank you for any ideas!

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-08-23T21:59:02.453+00:00

    The question is not clear to me. Does the CSV file has the mapping? In such case it sounds like a straight update to me.

    It could help if you posted CREATE TABLE for your tables (including one that represents the CSV file) and INSERT statements with sample data, so that we understand the problem better.

    0 comments No comments

  2. LiHongMSFT-4306 31,566 Reputation points
    2022-08-24T08:38:13.907+00:00

    Hi @AMber
    Try update with the Code table Join your CSV table, like this:

    UPDATE Code_Table  
    SET Column_name1 = Value1  
    FROM Code_Table JOIN CSV_Table ON ([Some ON Conditions Here])  
    

    Best regards,
    LiHong

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.