How to split single cell into multiple columns in sql server 2008R2?

前端 未结 2 588
天涯浪人
天涯浪人 2021-01-26 03:06

I want to split each name for individual columns

create table split_test(value integer,Allnames varchar(40))
insert into split_test values(1,\'Vinoth,Kumar,Raja,         


        
2条回答
  •  有刺的猬
    2021-01-26 03:22

    using this example you can get an idea.

    declare @str varchar(max)
    set @str = 'Hello world'
    
    declare @separator varchar(max)
    set @separator = ' '
    
    declare @Splited table(id int identity(1,1), item varchar(max))
    
    set @str = REPLACE(@str,@separator,'''),(''')
    
    set @str = 'select * from (values('''+@str+''')) as V(A)' 
    
    insert into @Splited
    exec(@str)
    select * from @Splited
    

提交回复
热议问题