Arrao4u

…a blog by Rama Rao

Archive for the ‘Split function in sql server’ Category

Split function in sql server

Posted by arrao4u on February 8, 2010

CREATE

FUNCTION dbo.Bikash(

@RowData

nvarchar(2000),@SplitOn

)

nvarchar(5) RETURNS

@RtnValue table (

Id

int identity(1,1),Data

)

nvarchar(100)AS

BEGIN

Declare

Set

@Cnt int @Cnt = 1While

(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 + 1End

Insert

Into @RtnValue (data)Select

Data = ltrim(rtrim(@RowData))Return

END

select

* from Bikash(’111-222-333-444′,‘-’) where id=2

Posted in Split function in sql server | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.