Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Seventhnight split funtion

Author  Topic 

paxmaster
Starting Member

4 Posts

Posted - 2009-01-12 : 23:58:13
I found the split function here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

I did some modification, I know what it does; but don't know how and why could please clarify it I am kinda new at this

alter FUNCTION dbo.Split

(

@RowData nvarchar(2000),

@SplitOn nvarchar(5)

)

RETURNS @RtnValue TABLE

(



DATA nvarchar(100)

)

AS

BEGIN

Declare @Cnt int

SET @Cnt = 1



While (Charindex(@SplitOn,@RowData)>0)

Begin

INSERT INTO @RtnValue (DATA)

SELECT

DATA = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))



SET @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))

SET @Cnt = @Cnt + 1

End



INSERT INTO @RtnValue (DATA)

SELECT DATA = ltrim(rtrim(@RowData))



RETURN

END

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-13 : 00:02:20
what it does is look for delimiter position each time and give data portion till delimiter. then it starts ooking from next position till next delimiter. this is continued until end of string and each time value extracted is put to table. in the end you get a table as result with inidividual values populated
Go to Top of Page
   

- Advertisement -