How to split a comma-separated value to columns

后端 未结 30 4045
刺人心
刺人心 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 05:00

    ;WITH Split_Names (Value,Name, xmlname)
    AS
    (
        SELECT Value,
        Name,
        CONVERT(XML,''  
        + REPLACE(Name,',', '') + '') AS xmlname
          FROM tblnames
    )
    
     SELECT Value,      
     xmlname.value('/Names[1]/name[1]','varchar(100)') AS Name,    
     xmlname.value('/Names[1]/name[2]','varchar(100)') AS Surname
     FROM Split_Names
    

    and also check the link below for reference

    http://jahaines.blogspot.in/2009/06/converting-delimited-string-of-values.html

提交回复
热议问题