• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

一个简单的存储过程

ggyy2002 2003-05-16 10:39:35
我要从数据库中返回指定的10条纪录
例如第20-29条开始的纪录号由参数传入,请教高手应如何实现
在线等!
...全文
7 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
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
回复
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
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-05-16 10:39
社区公告
暂无公告