SPLIT Function for SQL Server
Code: SQL
CREATE FUNCTION Split (@String nvarchar(4000), @Delimiter char(1))
Returns @Results TABLE (Items nvarchar(4000))
AS
Begin
   Declare @INDEX int
   Declare @Slice nvarchar(4000)
   SELECT @INDEX = 1
   IF @String IS NULL RETURN
   
   While @INDEX != 0
   Begin
 
      SELECT @INDEX = CharIndex(@Delimiter, @String)
      IF INDEX != 0
         SELECT @Slice = LEFT(@String, @INDEX - 1)
      else
         SELECT @Slice = @String
         INSERT INTO @Results(Items) VALUES (@Slice)
         SELECT @String = RIGHT(@String, Len(@String) - @INDEX)
      IF Len(@String) = 0 break
   End
   RETURN
End