Reputation: 3
I have a table T1:
code | name |
---|---|
001 | alias |
002 | row |
and I have a text file code.txt
oldCode;newCode
001;d4f
002;bc3
I need to update table t1 (replace the old code with the new code) and the table be like that:
code | name |
---|---|
d4f | alias |
bc3 | row |
Does anyone have the solution?
Upvotes: 0
Views: 2819
Reputation: 778
Taking Larnu's method, a query would be like:
UPDATE t SET t.code = DATA.newCode FROM T1 t JOIN OPENROWSET(BULK 'PATH_TO_FILE\code.txt', SINGLE_CLOB) AS DATA ON t.code = DATA.oldcode;
Keep in mind SQL server should have access to the file.
Upvotes: 1