Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL
 CREATE PROCEDURE GetCustomersPageWise
      @PageIndex INT = 1
      ,@PageSize INT = 10
      ,@RecordCount INT OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
      SELECT ROW_NUMBER() OVER
      (
            ORDER BY [CustomerID] ASC
      )AS RowNumber
      ,[CustomerID]
      ,[CompanyName]
      ,[ContactName]
     INTO #Results
      FROM [Customers]
     
      SELECT @RecordCount = COUNT(*)
      FROM #Results
           
      SELECT * FROM #Results
      WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
     
      DROP TABLE #Results
END
GO
i need same answere using common table expression only i am already got output
Posted 20 Sep '12 - 23:48
Edited 21 Sep '12 - 0:00

Comments
OriginalGriff - 21 Sep '12 - 5:53
This is not a good question - we cannot work out from that little what you are trying to do. Remember that we can't see your screen, access your HDD, or read your mind. Perhaps if you tell us what you expect to get? And what you actually get? Use the "Improve question" widget to edit your question and provide better information.
Sandeep Mewara - 21 Sep '12 - 5:56
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific. Use the "Improve question" link to edit your question and provide better information.

1 solution

Try this:
CREATE PROCEDURE GetCustomersPageWise
      @PageIndex INT = 1
      ,@PageSize INT = 10
      ,@RecordCount INT OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
      SELECT ROW_NUMBER() OVER
      (
            ORDER BY [CustomerID] ASC
      )AS RowNumber
      ,[CustomerID]
      ,[CompanyName]
      ,[ContactName]
     INTO #Results
      FROM [Customers]
     
      SELECT @RecordCount = (SELECT COUNT(*) FROM #Results)--Error
           
      SELECT * FROM #Results
      WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
     
      DROP TABLE #Results
END
GO
 

 
--Amit
  Permalink  
Comments
Sandeep Mewara - 21 Sep '12 - 5:57
You replied but how? I mean, how do you know what Op was looking for and what needed a fix? :confused:
_Amy - 21 Sep '12 - 6:54
As OriginalGriff already asked the OP to modify the question. I was just stepping through the code and I found one error which I solved and posted. That might be creating the problem for OP. I guessed. :)
Sandeep Mewara - 21 Sep '12 - 7:26
Cool! Have 5! Good one.
_Amy - 21 Sep '12 - 7:32
Thank you. :)

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 315
2 Slacker007 240
3 Maciej Los 240
4 Aarti Meswania 210
0 Sergey Alexandrovich Kryukov 8,953
1 OriginalGriff 7,134
2 CPallini 3,758
3 Rohan Leuva 3,036
4 Maciej Los 2,488


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid