How to split a comma-separated value to columns

后端 未结 30 3943
刺人心
刺人心 2020-11-21 04:38

I have a table like this

Value   String
-------------------
1       Cleo, Smith

I want to separate the comma delimited string into two colu

30条回答
  •  野性不改
    2020-11-21 04:57

    You can use a table-valued function STRING_SPLIT, which is available only under compatibility level 130. If your database compatibility level is lower than 130, SQL Server will not be able to find and execute the STRING_SPLIT function. You can change a compatibility level of the database using the following command:

    ALTER DATABASE DatabaseName SET COMPATIBILITY_LEVEL = 130
    

    Syntax

    SELECT * FROM STRING_SPLIT ( string, separator )
    

    see documentation here

提交回复
热议问题