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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -