tl:Namespace:iqqngress, tl:ImageName:text1/54445t6,
tl:collection:
stg-r2-pksa, tl:cmdb:AppID:6100762427,
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
How to split a string with special text or particular text from SQL column?
RAVITEJASRIDASYAM-3196
21
Reputation points
- I have a column with below data which contains multiple set of tags that starting with "tl:e1:"
- How can i split the data that contains tl:e1: into separate column.
SQL Server Other
14,494 questions
Accepted answer
-
Alexander Petree 150 Reputation points
2023-04-23T01:50:26.6633333+00:00
1 additional answer
Sort by: Most helpful
-
Anonymous
2023-04-24T03:05:56.8533333+00:00 You can try this query.
create table test(col varchar(max)); insert into test values('tl:Namespace:iqqngress, tl:ImageName:text1/54445t6, tl:collection:stg-r2-pksa, tl:cmdb:AppID:6100762427, 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') ;with T1 as( select value from test cross apply string_split(col,',') ),T2 as( select Ltrim(value) as [COLLECTION] from T1 ),T3 as( select * from T2 where [COLLECTION] like 'tl:collection:%' ),T4 as( select trim('tl:collection:' from [COLLECTION]) as [COLLECTION] from T3) select row_number()over(order by [COLLECTION]) as Rno,[COLLECTION] from T4;
Output:
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.