想要显示前2条记录,然后单击“下一步",然后显示下一条2条记录? [英] want to show top 2 record and when click next then its show next two record?
本文介绍了想要显示前2条记录,然后单击“下一步",然后显示下一条2条记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
要显示前2条记录,然后单击下一步",然后显示其下一条2条记录?
hi Friends,
want to show top 2 record and when click next then its show next two record?
推荐答案
您需要编写存储过程,如下所示:
You need to write Stored Procedure like this:
USE [A_TEST] --my database
GO
/****** Object: StoredProcedure [dbo].[GetMyData] Script Date: 05/05/2012 13:22:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Name
-- Create date: 2012-05-05
-- Description: Get top(count) records starting from x
-- =============================================
ALTER PROCEDURE [dbo].[GetMyData]
-- Add the parameters for the stored procedure here
@count int = 0,
@current int = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT TOP(@count) *
FROM [dbo].[Table_1]
WHERE ([ID] Not IN(SELECT TOP(@current) [ID] FROM [dbo].[Table_1]))
END
用法:
Usage:
DECLARE @RC int
DECLARE @count int
DECLARE @current int
-- TODO: Set parameter values here.
SET @count = 2
SET @current=0
EXECUTE @RC = [A_TEST].[dbo].[GetMyData]
@count ,@current
SET @count = 2
SET @current=2
EXECUTE @RC = [A_TEST].[dbo].[GetMyData]
@count ,@current
SET @count = 2
SET @current=4
EXECUTE @RC = [A_TEST].[dbo].[GetMyData]
@count ,@current
结果:
1.时间(@count=2
; @current=0
)
Results:
1. time (@count=2
; @current=0
)
1 Item 1<br />
2 Item 2<br />
2.时间(@count=2
; @current=2
)
2. time (@count=2
; @current=2
)
3 Item 3<br />
4 Item 4<br />
3.时间(@count=2
; @current=4
)
3. time (@count=2
; @current=4
)
5 Item 5<br />
6 Item 6
这篇关于想要显示前2条记录,然后单击“下一步",然后显示下一条2条记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文