0

I have a table called equipment and column called equip_identifier. in equip_identifier there are rows of computer equipment data like this:

equip_identifier
COMP-1356G
COMP-2537G
COMP-6787G
COMP-2583G
COMP-8064G
COMP-7643G
COMP-9072G

I have to replace the numbers in each row with different values I was given. for example:

COMP-1356G needs to be changed to COMP-2200G

COMP-2537G needs to be changed to COMP-5881G

what is the most efficient way to update all of these values if I have 700+ rows to update?

eshirvana
  • 23,227
  • 3
  • 22
  • 38

1 Answers1

0
CREATE TABLE equipment (
    equip_identifier VARCHAR(100)
);


INSERT INTO equipment (equip_identifier)
VALUES
    ('COMP-1356G'),
    ('COMP-2537G'),
    ('COMP-6787G'),
    ('COMP-2583G'),
    ('COMP-8064G'),
    ('COMP-7643G'),
    ('COMP-9072G');




UPDATE equipment
SET equip_identifier = 
    CASE 
        WHEN equip_identifier = 'COMP-1356G' THEN 'COMP-2200G'
        WHEN equip_identifier = 'COMP-2537G' THEN 'COMP-5881G'
        -- Add more WHEN conditions for other replacements
        ELSE equip_identifier -- Keep the original value if no replacement is specified
END;
Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60