create table #data(Text varchar(500))
insert into #data select 'tl:Namespace:ingress, tl:ImageName:text1/54445t6,tl:collection:stg-r2-pksa, tl:cmdb:AppID:1070242777, tl:collection:Privileged_Policy, tl:collection:prd-lv-v1-pksa,tl:Namespace:ingress-udp, tl:collection:prd-atl-a1-pks, tl:collection:dev-r2-pksa,tl:ImageName:text1/54445t6, tl:collection:nre-npdp1-pksa'
select * from #data
SELECT
row_number() over(order by (select null)) as SNo
, replace(value,'tl:collection:','') as COLLECTION
FROM
#data
cross apply
string_split(text,',')
WHERE
value like '%tl:collection:%'
; with cte_rn as
(
SELECT ROW_NUMBER() over( order by value) as rn , value FROM #data cross apply string_split(text,',') WHERE value like '%tl:collection:%' OR value like '%AppID%'
)
select
max(case when rn = 1 then replace(value,'tl:cmdb:AppID:','') end) as AppID
,max(case when rn = 2 then replace(value,'tl:collection:','') end) as Collection1
,max(case when rn = 3 then replace(value,'tl:collection:','') end) as Collection2
,max(case when rn = 4 then replace(value,'tl:collection:','') end) as Collection3
,max(case when rn = 5 then replace(value,'tl:collection:','') end) as Collection4
,max(case when rn = 6 then replace(value,'tl:collection:','') end) as Collection5
,max(case when rn = 7 then replace(value,'tl:collection:','') end) as Collection6
from cte_rn
Be careful here, folks. There is no guarantee of order using the STRING_SPLIT() function in versions prior to SQL Server 2022. It will "usually" appear to work but there are no guarantees.