I have in my application a user defined function which takes a comma separated list as an argument. It splits the items and plugs them in to a table variable and returns the result.
This function works well, except that when the items in the comma separated list exceed 1000, it ignores the remainder. That is to say, if I plug in 1239, the first 1000 rows will be returned and the remaining 239 are entirely ignored. There are no errors when this occurs.
I can't help but feel that this is due to some sort of limitation that I should know about, but I can't seem to find any information about it. Is it a limitation on the amount of rows that can be stored in a table variable? Or am I missing something in the actual code itself? Can anyone assist? Going squirrely-eyed over here.
ALTER FUNCTION [dbo].[ufnConvertArrayToIntTable] (@IntArray VARCHAR(8000))
RETURNS @retIntTable TABLE
(
ID int
)
AS
BEGIN
DECLARE @Delimiter char(1)
SET @Delimiter = ','
DECLARE @Item varchar(8)
IF CHARINDEX(@Delimiter,@IntArray,0) <> 0
BEGIN
WHILE CHARINDEX(@Delimiter,@IntArray,0) <> 0
BEGIN
SELECT
@Item = RTRIM(LTRIM(SUBSTRING(@IntArray,1,CHARINDEX(@Delimiter,@IntArray,0)-1))),
@IntArray = RTRIM(LTRIM(SUBSTRING(@IntArray,CHARINDEX(@Delimiter,@IntArray,0)+1,LEN(@IntArray))))
IF LEN(@Item) > 0
INSERT INTO @retIntTable SELECT @Item
END
IF LEN(@IntArray) > 0
INSERT INTO @retIntTable SELECT @IntArray
END
ELSE
BEGIN
IF LEN(@IntArray) > 0
INSERT INTO @retIntTable SELECT @IntArray
END
RETURN
END;