I have a table that has following text in a column and I need to convert the texts into multiple columns.
create table Test (
resource_type varchar(300)
);
insert into Test (resource_type) values
('Number of reservations: 1'),
('Number of reservations: 2 ¶ Perf ID: Event : 51680'),
('Number of reservations: 3 ¶ Perf ID: Event : 51683');
and I have converted this into columns by doing
Select A.*
,Pos1 = xDim.value('/x[1]' ,'varchar(100)')
,Pos2 = xDim.value('/x[2]' ,'varchar(100)')
From Test A
Cross Apply ( values (convert(xml,'<x>' + replace(A.resource_type,'¶','</x><x>')+'</x>')) )B(xDim)
Output of the code is
Instead, I need Number of reservations and PerfID as columns and under the number of reservations values as 1, 2, and 3 and under perf id null, 51680, and 51683...
Please help me how to proceed further!