Table with incorrect data in columns

Hello, I have imported some data into a table (from a spreadsheet) and it transpires that some of the source data was incorrect.

By that, I mean I have two columns: spend_reason and project_type. Spend_reason contains project_type data and project_type contains spend_reason data!

How can I get the data into the right columns? I can't do

UPDATE table SET project_type = spend_reason

because then I will lose the original values in project_type (which I then need to update the spend_reason column with).

Any thoughts appreciated. I do have a primary key in the table to identify each row.


hope this helps

one idea

RENAME COLUMN project_type to XYZ
RENAME COLUMN spend_reason to project_type
RENAME COLUMN XYZ to spend_reason

how to actually rename columns syntax
EXEC sp_rename 'dbo.ErrorLog.ErrorTime', 'ErrorDateTime', 'COLUMN';


Thank you, never thought of renaming the columns :slight_smile:

UPDATE table 
SET project_type = spend_reason, spend_reason = project_type
1 Like