Click here to Skip to main content
15,886,786 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,


CREATE PROCEDURE [dbo].[spStudentListPagination] 
    
     @start int = 0,
     @pageCount int=0

AS
BEGIN
   
     Set NOCOUNT ON
     SELECT TOP @pageCount * FROM 
     (
          SELECT 
       [STNO]
      ,[SNAME]
      ,[MAJOR]
      ,[CLASS]
      ,[BDATE]
      , ROW_NUMBER() OVER (ORDER BY STNO) AS num
      FROM [student_db].[dbo].[Student]
     ) AS a
     WHERE num > @start
END



it generating the error


Msg 102, Level 15, State 1, Procedure spStudentListPagination, Line 9
Incorrect syntax near '@pageCount'.
Msg 156, Level 15, State 1, Procedure spStudentListPagination, Line 19
Incorrect syntax near the keyword 'AS'.



when i am giving the direct value to @start and @pagecount The result is selecting the table data properly..
Posted

Hi Christian,

Try it out .

SQL
  CREATE PROCEDURE GetBranchesnyPage 
    
     @start int = 0,
     @pageCount int=0
 
AS
BEGIN
   
    
     Set NOCOUNT ON
     SELECT  * FROM 
     (
          SELECT 
       [Id]
      ,[BranchName]
      ,[CountryCode] 
      , ROW_NUMBER() OVER (ORDER BY Id) AS num
      FROM Branches
     ) AS A
     WHERE num > @start and num <=(@start+@pageCount)
END



I hope it can help you

All the best
 
Share this answer
 
Comments
Christian Graus 8-Jan-13 2:19am    
I did not ask the question, but this looks to me like it will sort of work. @start is the start index, not a page number.
Muralikrishna8811 8-Jan-13 2:24am    
yeah you are Right need some wrk to pass startindex and pagecount based on pageindex.
samu4u 8-Jan-13 2:23am    
Thanks...
Muralikrishna8811 8-Jan-13 2:26am    
Very welcome
SQL Server does not support this. Sadly, you need to create a line of SQL and use EXEC, to do this.
 
Share this answer
 
Comments
samu4u 8-Jan-13 2:18am    
how we can change this query like that !!
Christian Graus 8-Jan-13 2:20am    
What the other guy posted, is better.

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