peter

peter

  • NA
  • 320
  • 0

Union on SP with custom paging routine

Jul 7 2022 7:40 PM

At present i have the following SP code


SELECT TOP(@PageSize) * FROM 
(
 SELECT RowID = ROW_NUMBER() OVER (ORDER BY datentime DESC),
 RefID, InboxId, MessageType, SenderID, 
RecieverID, [Subject], Body, DatenTime,
TotalRows=Count(inboxid) OVER()

  
 FROM Inbox_Messages 

A WHERE  A.RowID > ((@PageIndex-1)*@PageSize) order by datentime DESC

I want to introduce another table that has same column included as Inbox_Messages so that the result set displays both table data.

I understand that this can be achieved using a UNION. The problem is there is two extra entries namely TotalRows and RowID therefore the two tables do not have matching columns.So how may i reconfigure so that it returns correct paged data?

New table addition

 SELECT 
 
    RefID,
InboxID,
  MessageType,
  SenderID,
  RecieverID,
  [Subject],
  Body,
  Datentime
   
  FROM Inbox_Return


Answers (1)