Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:51:57+00:00 2026-05-23T12:51:57+00:00

ALTER PROCEDURE [dbo].[getMessages] — Add the parameters for the stored procedure here @lastRow int,

  • 0
ALTER PROCEDURE [dbo].[getMessages]
    -- Add the parameters for the stored procedure here
    @lastRow int,
    @sort varchar(9)
AS
BEGIN
    -- Insert statements for procedure here
    DECLARE @StartRow INT,@EndRow INT
    SELECT @StartRow = (@lastRow + 1), @EndRow = (@lastRow + 6)

;WITH cte AS (SELECT ROW_NUMBER() OVER (ORDER BY
        CASE WHEN @sort = 'votes1' THEN m.votes END DESC,
        CASE WHEN @sort = 'votes2' THEN m.votes END ASC
      ) AS rows,
      m.message,
      m.messageId,
      TotalCount = COUNT(m.messageId) OVER ( PARTITION BY NULL)
    FROM
      tblMessages m
    WHERE
      m.deleted != 1
      )
     SELECT * 
     FROM cte WHERE ROWS BETWEEN @StartRow AND @EndRow
    ORDER BY rows
END

So this is my proc that I use for paging so on the front end I can pass in the last row I saw, and then when I click “load more”, it starts from the next row and gets the next 6. Well, not I want the PREVIOUS 6, passing in an id, so if you see 6, go to the next six, and then want to see the previous 6 again.

How would I modify this proc to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:51:58+00:00Added an answer on May 23, 2026 at 12:51 pm

    You don’t.

    Instead, modify your code. The key in the proc is the @lastrow. When you execute it the first time I’m assuming @lastrow = 0. If they go forward, you are executing it with a value of 6.

    To go backward, just pass the current value – 6. For example, if you’re on page 20, @lastrow is going to be 114. Subtract 6 in your code and call the proc again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for example... ALTER PROCEDURE [dbo].[Reports_Dashboard_Get_Sav] -- Add the parameters for the stored procedure here
ALTER PROCEDURE [dbo].[USP_ViewRegForm] -- Add the parameters for the stored procedure here ( @RegFormID
--Stored procedure ALTER PROCEDURE [dbo].[Test] @USERID varchar(25) AS BEGIN SET NOCOUNT ON IF NOT
ALTER PROCEDURE [dbo].[test] @tour int, @tourname varchar(50) OUTPUT, @tourdepartures varchar(50) OUTPUT AS BEGIN --
I've a stored procedure here ALTER PROCEDURE [dbo].[SortedReport] ( @ClientID INT, @RecordLimit, @FromDate DATETIME,
My stored procedure is: ALTER PROCEDURE [dbo].[Insert_QuickLabDump] @Specimen_ID [varchar](50), @Client_Key int, @Outcome [varchar](50), @Medications
Here's my SQL Server stored procedure : ALTER PROCEDURE [dbo].[SearchUser] (@Text NVARCHAR(100), @TotalRows INT
I wrote the following stored procedure: ALTER PROCEDURE [dbo].[spLinkAssetToModule] ( -- Add the parameters
My insert stored procedure: ALTER procedure proj_ins_all ( @proj_number INT, @usr_id INT, @download DATETIME,
I have the following stored procedure ALTER PROCEDURE [dbo].Test AS BEGIN CREATE TABLE ##table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.