sql server 2008 - T-SQL split string -


i have sql server 2008 r2 column containing string need split comma. have seen many answers on stackoverflow none of them works in r2. have made sure have select permissions on split function examples. appreciated.

i've used sql before may work you:-

create function dbo.splitstring ( @stringtosplit varchar(max) ) returns  @returnlist table ([name] [nvarchar] (500)) begin   declare @name nvarchar(255)  declare @pos int   while charindex(',', @stringtosplit) > 0  begin   select @pos  = charindex(',', @stringtosplit)     select @name = substring(@stringtosplit, 1, @pos-1)    insert @returnlist    select @name    select @stringtosplit = substring(@stringtosplit, @pos+1, len(@stringtosplit)-@pos)  end   insert @returnlist  select @stringtosplit   return end 

and use it:-

select * dbo.splitstring('91,12,65,78,56,789') 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -