Here is the Function, Just copy, paste and enjoy..
create function [dbo].[SplitGETPos](
@String varchar(1000),
@Delimiter char(1),
@POSITION INT)
returns varchar(20)
as
begin
declare @OUTPUT varchar(20);
declare @idx int;
DECLARE @CHARIDX INT;
DECLARE @INPUTSTR VARCHAR(1000);
SET @INPUTSTR=@String + ',';
SET @CHARIDX =0;
SET @idx=0;
while @idx < @POSITION
begin
SET @CHARIDX= CHARINDEX(@Delimiter, @INPUTSTR);
SET @OUTPUT=SUBSTRING(@INPUTSTR, 1, @CHARIDX - 1)
SET @INPUTSTR = SUBSTRING(@INPUTSTR,@CHARIDX +1,LEN(@INPUTSTR));
SET @idx=@idx+1;
end
return @OUTPUT
end
Thanks
--RA