CSDN博客

img slightboy

MSSQL 存储过程分页 测试 2

发表于2004/10/18 14:53:00  653人阅读

中间件 稍微做了修改 作为记录
后面改用另一种方法了

DECLARE @User_Condition varchar(500)
DECLARE @User_Sort varchar(20)
DECLARE @User_Rank varchar(4)

DECLARE @TotalRecord int
DECLARE @Page_Size real
DECLARE @Page_Count real
DECLARE @Page_Order int
DECLARE @SQLQuery varchar(1000)

DECLARE @del_error int
DECLARE @ins_error int

Set @Page_Size = 10
Set @Page_Count = CEILING(@TotalRecord/@Page_Size)
Set @Page_Order = 55

Set @User_Sort = 'Digitaltion_ID'
Set @User_Rank = 'Desc'

IF (@Page_Order > @Page_Count/2)
  IF (@User_Rank = 'Asc')
    BEGIN
      Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE Digitaltion_ID IN (SELECT TOP '+ STR(@TotalRecord - (@Page_Order - 1) * @Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Desc) ORDER BY '+ @User_Sort +' Asc'
    END
  Else
    BEGIN
      Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE Digitaltion_ID IN (SELECT TOP '+ STR(@TotalRecord - (@Page_Order - 1) * @Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Asc) ORDER BY '+ @User_Sort +' Desc'
    END

Else
  IF (@User_Rank = 'Asc')
    BEGIN
    Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE Digitaltion_ID NOT IN (SELECT TOP '+ STR((@Page_Order - 1) * @Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Asc) ORDER BY '+ @User_Sort +' Asc'
    END
  Else
    BEGIN
    Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE Digitaltion_ID NOT IN (SELECT TOP '+ STR((@Page_Order - 1) * @Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Desc) ORDER BY '+ @User_Sort +' Desc'
    END

SELECT @Page_Count AS Page_Count, @Page_Size AS Page_Size, @Page_Order AS Page_Order
SELECT @SQLQuery
EXECUTE(@SQLQuery)
GO

阅读全文
0 0

相关文章推荐

img
取 消
img