http://reddymsbitools.blogspot.com

Saturday, 26 February 2011

Function for getting comma seperator

SET
QUOTED_IDENTIFIER ON

GO

/*

Name: CommaSeperator

Description: This function will seperate the string parameters.

Modification History

Date By Description

---------- --------------------- -----------------------------------------------

04/03/2009 Paradigm Infotech Inc. Initial Version created

Copyright [2009] New England BioLabs, Inc. All rights reserved.

*/

create
function [dbo].[CommaSeperator]

(

@stringToBreak varchar
(4000),

@limiter
char(1)

)

returns @list
table (item varchar(4000))

as

begin

if (charindex(@limiter,@stringToBreak) = 0)

begin

insert into @list values (@stringToBreak)

return

end

declare @list1 varchar(4000)

declare @charIndex int

declare @TempItems table (item varchar(4000))

set @charIndex = charindex(@limiter,@stringToBreak)

while len(@stringToBreak) > 0 and @charIndex <> 0

begin

select @list1 = ltrim(left(@stringToBreak,@charIndex - 1))

insert @tempItems select @list1

select @stringToBreak = ltrim(right(@stringToBreak, len(@stringToBreak) - @charIndex))

set @charIndex = charindex(@limiter,@stringToBreak)

end

insert @tempItems select @stringToBreak

insert @list select Item from @tempItems

return

end

No comments:

Post a Comment