一个简单的存储过程

ggyy2002 2003-05-16 10:39:35
我要从数据库中返回指定的10条纪录
例如第20-29条开始的纪录号由参数传入,请教高手应如何实现
在线等!
...全文
65 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
leimin 2003-05-16
  • 打赏
  • 举报
回复
CREATE PROCEDURE GetProductsPaged
@lastProductID int,
@pageSize int
AS
SET ROWCOUNT @pageSize
SELECT *
FROM Products
WHERE [standard search criteria]
AND ProductID > @lastProductID
ORDER BY [Criteria that leaves ProductID monotonically increasing]
GO
愉快的登山者 2003-05-16
  • 打赏
  • 举报
回复
create procedure p1 @i int, @j int
as
exec ("select * from a1 as A where (select count(id) from a1 where id <= A.id)
between " +cast(@i as varchar)+" and " + cast(@j as varchar)+ " order by id")
go

ggyy2002 2003-05-16
  • 打赏
  • 举报
回复
wgy2008(北极光) 生成临时表,会不会太占资源,
这个存储过程需要经常使用
CrazyFor 2003-05-16
  • 打赏
  • 举报
回复
查询N-M条记录。
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
select top M-N * from #temptable where iid>=N

OR:

select top M-N * from yourTable where id not in(select top N-1 id from table)
ID为表具有唯一值的任何字段
wgy2008 2003-05-16
  • 打赏
  • 举报
回复
create procedure @kk int
as
SELECT 列1,列2.....,IDENTITY(smallint, 100, 1) AS job_num
INTO #t
FROM 表
select top 10 *
from #t
where job_num >= @kk
愉快的登山者 2003-05-16
  • 打赏
  • 举报
回复
select * from a1 as A where
(select count(id) from a1 where id <= A.id)
between 20 and 29 order by id

select id from
(select top 10 * from
(select top 29 * from a1 order by id) as A
order by A.id desc) as B order by B.id asc

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧