Click here to Skip to main content
15,919,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I Tried the below and i can get the frist 3 string split by _, but when i tried to 'FBC_asda_CB_All_Quota_A01' its not working.

can someone help me to split the 'FBC_asda_CB_All_Quota_A01'

Thanks in advance.

What I have tried:

with t as (select 'FBC_abc_CB' as val)
select t.*,
LEFT(val, charindex('_', val) - 1),
SUBSTRING(val, charindex('_', val)+1,
len(val) - CHARINDEX('_', reverse(val)) - charindex('_', val)),
REVERSE(LEFT(reverse(val), charindex('_', reverse(val)) - 1))
from t;
Posted
Updated 22-Aug-18 19:17pm
Comments
Patrice T 22-Aug-18 22:56pm    
What should be the result of 'FBC_asda_CB_All_Quota_A01' ?

1 solution

Simple splitting isn't difficult, just messy because SQL string handling is at best poor: Converting comma separated data in a column to rows for selection[^]
Replacing commas with underscores should do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900