Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having pagination issue on executing below sql query. records from 1 to 10 are shown but on pagination same sequence is coming

What I have tried:

My query is as below:
DECLARE @ip_Process varchar(20)

DECLARE @p_PageNo INT
,@p_PageSize   INT
,@TimeInterval INT

DECLARE @TopRecords INT
DECLARE @LeftStart INT


--Top records to be read
SET @TopRecords= (@p_PageNo + 1) * @p_PageSize

--Starting records from left
SET @LeftStart= (@p_PageNo) * @p_PageSize



SELECT
TOP ( @TopRecords) ROW_NUMBER() OVER (ORDER BY Slnum ) AS SlnO,
[ID]
,ProcessName
,TableName --Updated as per Onsite Need on 21.6.2021
,ProcessCode
,NodeName,
Timestamp
FROM(

SELECT
ROW_NUMBER() OVER (ORDER BY [ID] ) AS Slnum,
[ID]
,ProcessName
,TableName --Updated as per Onsite Need on 21.6.2021
,ProcessCode
,NodeName,
Timestamp
FROM(



SELECT
[UBSPostingID] as ID
,'UBS Inward Process' as ProcessName
--Updated as per Onsite Need on 21.6.2021 Start
,'DDS_UBSPostingsQueue' as TableName
--Updated as per Onsite Need on 21.6.2021  End
,'11' as ProcessCode
,NodeName,
Timestamp
FROM
DDS_UBSPostingsQueue
WHERE  ISNULL(NodeName,'')!='' AND ISNULL(Timestamp ,'')!=''
AND (DATEADD(MINUTE,@TimeInterval,Timestamp)) < GETDATE() --Timestamp<(DATEADD(MINUTE,@TimeInterval,GETDATE()))

Union All


SELECT
[SFTPFileId] as ID
,'SFTP Upload' as ProcessName
--Updated as per Onsite Need on 21.6.2021 Start
,'DDS_SFTPFileTransferQueue' as TableName
--Updated as per Onsite Need on 21.6.2021  End
,'12' as ProcessCode
,NodeName,
Timestamp
FROM
DDS_SFTPFileTransferQueue
WHERE  ISNULL(NodeName,'')!='' AND ISNULL(Timestamp ,'')!=''
AND (DATEADD(MINUTE,@TimeInterval,Timestamp)) < GETDATE() --Timestamp<(DATEADD(MINUTE,@TimeInterval,GETDATE()))

) p
WHERE (P.ProcessCode=@ip_Process OR @ip_Process='') ) PR WHERE Slnum> @LeftStart
Posted
Updated 22-Jun-21 9:08am

1 solution

Multiple levels of nested SQL (via FROM) ? ? ?

What do you do to retrieve the top records by actually using
@TopRecords= (@p_PageNo + 1) * @p_PageSize and SET @LeftStart= (@p_PageNo) * @p_PageSize ?

Aside from the poor (in my opinion) design of the query, you seem to be asking for the same data and so that what you get.

Depending upon your database (SQL, MySQL, etc.) you can (for example) generate a numbering function in a column and the request based upon the position in the returned data. Possibly build into a #tmp table and draw your data from that, it having the generated record enumeration column.


 
Share this answer
 

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