MSSQL store procedure paging test 1

xiaoxiao2021-03-06  79

There is no careful test only to study the algorithm to study the algorithm of the stored procedure paging of others, plus the declare @totalRecord realdeclare @page_size realdeclare @page_count realdeclare @Page_Order INTDECLARE @SqlQuery varchar (1000)

SELECT @ TotalRecord = Count (DIGITALTION_ID) from [DigitalArt_Digitaltion]

Set @Page_Size = 2set @Page_count = CEILING (@ TotalRecord / @ Page_Size) SELECT @PAGE_COUNT AS Page_Size, @page_order as page_order

IF (@Page_Order> @ Page_Count / 2) BEGIN Set @SQLQuery = 'SELECT TOP' Cast (@Page_Size AS varchar (30)) 'Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE Digitaltion_ID IN (SELECT TOP' CAST (@TotalRecord - (@Page_Order - 1) * @ Page_Size AS varchar (30)) 'Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY Digitaltion_ID Asc) ORDER BY Digitaltion_ID Desc' ENDElse BEGIN Set @SQLQuery = 'SELECT TOP' Cast (@Page_Size AS varchar ( 30)) 'Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE Digitaltion_ID NOT IN (SELECT TOP' CAST ((@ Page_Order-1) * @ Page_Size AS varchar (30)) 'Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY Digitaltion_ID Desc) ORDER BY Digitaltion_id desc 'endselect @SqlQueryexec (@sqlQuery) Go

转载请注明原文地址:https://www.9cbs.com/read-104924.html

New Post(0)