SQL 服务器错误?
我正在编写一个函数来处理一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了保证 SQL Server 中的排序顺序,您必须使用 ORDER BY 子句。
按条款排序
In order to gaurantee sort order in SQL Server you must use the ORDER BY clause.
ORDER BY CLAUSE