sql server2000 中的怎样查询指定行之间的数据

来源:百度知道 编辑:UC知道 时间:2024/05/19 02:43:21
我想提起查询结果集中的指定行之间的数据,向mysql中的(select * from product limit 1,2)limit关键字执行的那样。。。。。
没有准确答案的勿扰。。。
经过努力,总算找到了可以实现的方法,但是有一点小的问题,请高手帮忙.
那就是关键字top后面若要跟数字到好,没有错,但要是换在存储过程里,top后面跟变量就不行的,代码如下:
/*product为表名,*/
create proc getMidData
(
@p int,/*当前页码*/
@ps int/*每页显示的条数*/
)
as
set rowcount @ps/*设置提取的数据条数为每页显示的条数*/
declare @topNum as int/*声明变量topNum*/
set @topNum=@p*@ps/*为变量赋值*/
select * from product where productId
not in/*设置要排除的数据集合*/
(
select top @topNum productId from product/*选择前topNum行的数据*/
order by selectDate desc
)
order by selectDate desc

报错如下:
服务器: 消息 170,级别 15,状态 1,过程 getMidData,行 13
第 13 行: '@topNum' 附近有语法错误。

sql server2000中,没有按行号提取结果的SQL语句,只能把数据按一定方式排序后,取前几条,取不了中间的:

select top n * from product

或者给product加ID,然后按ID来取。

其他除非自己写存贮过程了,但那也不是LZ想要的答案。

select * from (select row_.*, rownum rownum_ from
(select * from scott.admin order by id)row_ where rownum <=10) where rownum_ >4;
这个是oracle的
不知道在sql server2000中是否管用