By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create TABLE StudentClass(
name [nvarchar](30) NULL,
class [nvarchar](100) NULL,
)
insert into StudentClass
values ('Anne', 'Math;Art;Art History'),
('Bill', 'Math;English'),
('Charlie', 'English'),
('Daisy', 'English;Art;Art History'),
('Eddy', 'Math;Art')
5 rows affected
update StudentClass set class = replace(class, 'Math', '001')
update StudentClass set class = replace(class, 'English', '002')
update StudentClass set class = replace(class, 'Art', '003')
update StudentClass set class = replace(class, 'Art History', '004')
20 rows affected
SELECT * FROM StudentClass
name | class |
---|---|
Anne | 001;003;003 History |
Bill | 001;002 |
Charlie | 002 |
Daisy | 002;003;003 History |
Eddy | 001;003 |