Logic to Split the data in a Table

I have a table as below

create table #TempEmp
(
ID int,
Name varchar(25),
Code varchar (25)
)

insert into #TempEmp(ID,Name,Code )
select 100,'Steve','A,B,W' union all
select 100,'Steve','D,W,X'

I would like to get the final table split the records based on 'Code' data.Final table should look like below.
insert into #TempEmp(ID,Name,Code )
select 100,'Steve','A' union all
select 100,'Steve','B' union all
select 100,'Steve','W' union all
select 100,'Steve','D' union all
select 100,'Steve','W' union all
select 100,'Steve','X'

Appreciate anyone's help.Thanks in advance!

Take a look at: STRING_SPLIT (Transact-SQL) - SQL Server | Microsoft Learn

1 Like

Thank You @jeffw8713 .