SQL 字串轉TABLE

SQL 字串轉TABLE

CREATE   function   [dbo].[ufnSplit](@c   varchar(max),@split   varchar(2))   
  returns   @t   table(col   varchar(20))   
  as   
    begin   
    
      while(charindex(@split,@c)<>0)   
        begin   
          insert   @t(col)   values   (substring(@c,1,charindex(@split,@c)-1))   
          set   @c   =   stuff(@c,1,charindex(@split,@c),'')   
        end   
      insert   @t(col)   values   (@c)   
      return   
    end