How to split a comma-separated value to columns

后端 未结 30 4029
刺人心
刺人心 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:56

    With SQL Server 2016 we can use string_split to accomplish this:

    create table commasep (
     id int identity(1,1)
     ,string nvarchar(100) )
    
    insert into commasep (string) values ('John, Adam'), ('test1,test2,test3')
    
    select id, [value] as String from commasep 
     cross apply string_split(string,',')
    

提交回复
热议问题