Sunday, 25 February 2018

Write a function to split comma's in Sql Server

Drop function dbo.SplitingCommas
Go
Create function dbo.SplitingCommas(@String nvarchar(4000), @Delimiter char(1))
Returns @Results Table (Id int identity(1,1),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

1 comment:

  1. King casino review | Vegas Casino - VieCasino
    King Casino review, including real players' reviews and ratings, games, complaints, latest bonus codes, fun88 vin promotions and vua nhà cái promotions. 우리카지노 Rating: 4.3 · ‎18 votes

    ReplyDelete