mgmhicks
asked on
SQL Function not working properly
I have the following function that seems to work outside of the fact that if my list gets to long it doesn't seem to pull the propertyid's after a certain point. Can anyone tell my why this would work 'HC,SM,WG,KG,CL,NH,CM,CH,C W,GO,KA,RL ,SO,OF,WP, CG,PP,BF,C S' but this will not
'HC,SM,WG,KG,CL,NH,CM,CH,C W,GO,KA,RL ,SO,OF,WP, CG,PP,BF,C S,DT,HT,HP ,L1,L2,BW, B1,B2,BR,W A,WN,WT,SP ,ME,JP,PV'
Here is the code and
thanks in advance for the help
'HC,SM,WG,KG,CL,NH,CM,CH,C
Here is the code and
ALTER Function [dbo].[fn_Txt_Split](
@sInputList varchar(max) -- List of delimited items
, @Delimiter char(1) = ',' -- delimiter that separates items
)
RETURNS @list table (Item varchar(max))
as begin
DECLARE @Item Varchar(max)
WHILE CHARINDEX(@Delimiter,@sInputList,0) <> 0
BEGIN
SELECT
@Item=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@Delimiter,@sInputList,0
)-1))),
@sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@Delimiter,@sInputList,0)+1,LEN(@sInputList))))
IF LEN(@Item) > 0
INSERT INTO @List SELECT @Item
END
IF LEN(@sInputList) > 0
INSERT INTO @List SELECT @sInputList -- Put the last item in
return
END
thanks in advance for the help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER