create table CaseCode(
caseID int, Code varchar(10))
insert into CaseCode values
(1 ,'AAA')
,(1 ,'BBB')
,(1 ,'CCC')
,(1 ,'DDD')
,(2 ,'CCC')
,(3 ,'AAA')
,(3 ,'BBB')
,(3 ,'CCC')
,(3 ,'DDD')
,(3 ,'EEE')
select * from CaseCode
select caseID, AAA as code1,BBB as code2,CCC as...