How to use string_split with multiple delimiter

Lylyy 380 Reputation points
2023-09-27T02:47:21.06+00:00

Suppose the string values are separated by different delimiters like ',' '&' ';', then could we use string_split in this case?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,675 questions
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 26,706 Reputation points
    2023-09-27T02:58:57.0233333+00:00

    Hi @Lylyy

    could we use string_split in this case?

    Yes, you could use Replace to turn these different delimiters to same and then use String_split.

    Please check this sample:

    DECLARE @string varchar(max) = 'AAA, BBB & CCC DDD;EEE'    
    
    SELECT * 
    FROM STRING_SPLIT(REPLACE(REPLACE(REPLACE(@string,' ',','),';',','),'&',','),',')
    WHERE value <> ''
    

    Best regards,

    Cosmog Hong


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.