SQL 服务器错误?

发布于 2024-08-02 13:44:31 字数 918 浏览 5 评论 0原文

我正在编写一个函数来处理一些 CSV 数据。这是我到目前为止所写的...

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

我的问题是,当我执行该函数时,使用以下命令...

SELECT * FROM FGetCommaSeperatedValues('')

返回的表没有显示我期望的结果。

一切都很好,直到大约第 3624 行左右(如预期,id 列增加 1) 然后这些值会不规则地增加。

我的同事在 SQL Server 2008 中测试了这段代码,一切正常。这似乎与 SQL Server 2000 无关。

有谁知道这个错误和/或其解决方案吗?

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 issue is that when I execute the function, using the following command...

SELECT * FROM FGetCommaSeperatedValues('')

The table returned does not show the results that I expect.

Everything is fine until around row 3624 or so (as expected, id column increments by 1)
Then the values increment erratically.

My colleague tested this code in SQL Server 2008 and everything works fine. This appears to be isolated to SQL server 2000.

Does anyone know of this bug, and/or it's resolution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最近可好 2024-08-09 13:44:31

为了保证 SQL Server 中的排序顺序,您必须使用 ORDER BY 子句。

按条款排序

In order to gaurantee sort order in SQL Server you must use the ORDER BY clause.

ORDER BY CLAUSE

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文