SQL Server 2000 上的 SQL Server ROW_NUMBER()?
我有一个查询,允许我通过给定最小和最大限制来从数据库表中获取记录。
它是这样的:
SELECT T1.CDUSUARIO, T1.DSALIAS, T1.DSNOMBRE_EMPRESA, T1.DSCARGO, T1.DSDIRECCION_CORREO, T1.CDUSUARIO_ADMINISTRADOR, T1.FEMODIFICACION
FROM (SELECT *,
ROW_NUMBER() OVER (ORDER BY CDUSUARIO) as row FROM TBL_USUARIOS ) as T1
WHERE row > @limiteInf
and row <= @limiteSup
ORDER BY DSALIAS ASC;
现在,它在 SQL Server 2005 和 SQL Server 2008 上运行得像天堂一样,但尝试在 SQL Server 2000 数据库上运行它并显示:
ROW_NUMBER 这是一个未知的函数名称或类似名称。
我能做些什么??
I have a query that allows me to get records from a database table by giving it a minimum and maximum limit.
It goes like this:
SELECT T1.CDUSUARIO, T1.DSALIAS, T1.DSNOMBRE_EMPRESA, T1.DSCARGO, T1.DSDIRECCION_CORREO, T1.CDUSUARIO_ADMINISTRADOR, T1.FEMODIFICACION
FROM (SELECT *,
ROW_NUMBER() OVER (ORDER BY CDUSUARIO) as row FROM TBL_USUARIOS ) as T1
WHERE row > @limiteInf
and row <= @limiteSup
ORDER BY DSALIAS ASC;
Now, it works like heaven on SQL Server 2005 and SQL Server 2008 but tried to run it on an SQL Server 2000 database and says:
ROW_NUMBER it's an unknown function name or something like that.
What can I do??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这两种解决方案都不支持 PARTITION BY
我没有提到基于循环或 CURSOR 的解决方案,这些解决方案可能更糟糕
编辑 20011 年 5 月 20 日
为什么 IDENTITY 不起作用的示例演示:
插入的记录是否始终接收连续的标识值
Neither solution will support PARTITION BY
I've not mentioned loop or CURSOR based solutions which are probably worse
Edit 20 May 20011
Example demo of why IDENTITY won't work:
Do Inserted Records Always Receive Contiguous Identity Values
我知道这个线程有点旧,但对于寻找相同解决方案的其他人来说,我认为知道这个问题有一个好的解决方案将会很有用。
请参阅此处的原始链接
对于那些不想点击链接,我复制并粘贴了下面的代码。再次强调,功劳归于原始发布者
以下是 SQL Server 2000 的 SQL选择按单列分组的记录的最新版本。
SQL Server 2005 中的相同代码如下所示:
I know this thread is bit old, but for anyone else looking for same solution, I think it will be useful to know that there is a good solution for this problem.
Please see the original link here
For those who do not want to click on the link, I have copied and pasted the code below. Again, credit goes to original publisher
Here is the below SQL for SQL Server 2000 to select the latest version of a record grouping by a single column.
Same code in SQL Server 2005 would look like this:
使用其他功能或升级数据库。 ROW_NUMBER 在 2000 版本的数据库中并不存在。观点。你对此无能为力。
Use another function or upgrade your database. ROW_NUMBER did not exist back in the 2000 version of the database. Point. Nothing you can do about it.
这是我对问题的解决方案:
说明:
你可能会问,为什么我不在 select 语句中使用变量呢?会更简单但是不允许,除非没有结果。在更新中做到这一点就可以了。
This is my solution to the problem:
Explanation:
You may ask, why don't i use the variable in the select statement? It would be simpler but it's not allowed, only if there is no result. It's ok to do it in an update.