SQL Server error?

I am writing a function to process some CSV data. This is what I have written so far ...

CREATE FUNCTION dbo.FGetCommaSeperatedValues(@csv as text)
RETURNS @tblIds TABLE(id int,csvlength int) 
AS
BEGIN
    DECLARE @csvlength AS int
    --SET @csvlength = datalength(@csv);
    SET @csvlength = 7685
    DECLARE @currentIndex AS int
    SET @currentIndex = 0
        WHILE @currentIndex < @csvlength
            BEGIN
                --INSERT INTO @tblIds SELECT @currentIndex,@csvlength
                INSERT INTO @tblIds (id,csvlength) values (@currentIndex,@csvlength)
                SET @currentIndex = @currentIndex+1
            END
    RETURN
END

      

My problem is when I execute a function using the following command ...

SELECT * FROM FGetCommaSeperatedValues('')

      

The returned table does not show the expected results.

Everything is fine as long as around row 3624 or so (as expected, the number of columns increases by 1) Then the values ​​change erratically.

A colleague of mine tested this code in SQL Server 2008 and everything works fine. This seems to be isolated from SQL Server 2000.

Does anyone know about this error and / or its resolution?

+2


source to share


1 answer


To make the gaurantee sort order in SQL Server you must use the ORDER BY clause.



ORDER BY CLAUSE

+4


source







All Articles