Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi Friends,

want to show top 2 record and when click next then its show next two record?
Posted
Comments
thursunamy 5-May-12 1:23am    
Can you explain by details please ? From where ? WinForms,WebForms etc
Sandeep Mewara 5-May-12 2:59am    
Apart from above comment, did you try anything?
Member 8475177 5-May-12 13:43pm    
Reason for my vote of 5
best

1 solution

You need to write Stored Procedure like this:
SQL
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:
SQL
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


Results:
1. time (@count=2; @current=0)
1	Item 1<br />
2	Item 2<br />

2. time (@count=2; @current=2)
3	Item 3<br />
4	Item 4<br />

3. time (@count=2; @current=4)
5	Item 5<br />
6	Item 6
 
Share this answer
 
Comments
guptaadeepak 5-May-12 9:14am    
thanks losmac but i want with out not in because if i am click 10 time view more then not in string is long and its take too much time do u have any other alternative?
Maciej Los 5-May-12 12:07pm    
I don't uderstand you :( Do you know the rules of punctuation?
Please, be more specific and write exactly what you want, the structure of database and other important stuff...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900