5 de octubre de 2011

Función SPLIT

CREATE FUNCTION dbo.Split(@String varchar(8000), @Delimiter char(1))      
returns @temptable TABLE (items varchar(8000))      
as      
begin      
    declare @idx int      
    declare @slice varchar(8000)      
     
    select @idx = 1      
        if len(@String)<1 or @String is null  return      
     
    while @idx!= 0      
    begin      
        set @idx = charindex(@Delimiter,@String)      
        if @idx!=0      
            set @slice = left(@String,@idx - 1)      
        else      
            set @slice = @String      
         
        if(len(@slice)>0) 
            insert into @temptable(Items) values(@slice)      
 
        set @String = right(@String,len(@String) - @idx)      
        if len(@String) = 0 break      
    end  
return      
end 
Select top 10 * from dbo.split('Chennai,Bangalore,Mumbai',',') 

1 comentario:

  1. I cannot thank lemeridian funding service enough and letting people know how grateful I am for all the assistance that you and your team staff have provided and I look forward to recommending friends and family should they need financial advice or assistance @ 1,9% Rate for Business Loan .Via Contact : . lfdsloans@lemeridianfds.com / lfdsloans@outlook.com. WhatsApp...+ 19893943740. Keep up the great work.
    Thanks, Busarakham.

    ResponderEliminar