title: SQL Proc Modification Question
body: <pre><code>ALTER PROCEDURE [dbo].[spGetMessages]
      @lastRow int
  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,
          CASE WHEN @sort = 'age1' THEN datediff(minute,m.timestamp, getdate()) END ASC,
          CASE WHEN @sort = 'age2' THEN datediff(minute,m.timestamp, getdate()) END DESC
        ) AS rows,
        m.message,
        m.messageId
      FROM
        tblMessages m
      WHERE
        m.deleted != 1
        )
       SELECT * 
       FROM cte WHERE ROWS BETWEEN @StartRow AND @EndRow
      ORDER BY rows
  END
  </code></pre>
  
  <p>So this proc gets me a bunch of messages, but passing in the last row value so I can implement paging, and a 'load more' functionality on the front end.</p>
  
  <p>If the proc returns less than 6 messages, I can disable 'load more' obviously, if it returns 6 messages however, I don't know if there's more in the database, or that those were the last 6 messages.</p>
  
  <p>My thought was that if I passed back another <code>DataTable</code> containing either <code>true</code> or <code>false</code> that represented if there were more than these 6 messages left in the database using the last row id, I could use this flag to enable/disable the 'load more' button. Is this a good idea? If not, what's a better plan?</p>
  
  <p>If so, how would I modify this proc to pass that flag back?</p>