CSDN博客

img slightboy

MSSQL 存储过程分页 测试 3

发表于2004/10/18 15:11:00  608人阅读

分类: MSSQL

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

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

Set @Page_Size = 10
Set @Page_Order = 1

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

IF (@Page_Order > 0)
  IF (@User_Rank = 'Asc')
    BEGIN
      Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE (Digitaltion_ID > (SELECT MAX(Digitaltion_ID) FROM (SELECT TOP '+ STR(@Page_Order * @Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Asc) AS TeamTable)) ORDER BY '+ @User_Sort +' Asc'
    END
  Else
    BEGIN
      Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] WHERE (Digitaltion_ID < (SELECT MIN(Digitaltion_ID) FROM (SELECT TOP '+ STR(@Page_Order * @Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Desc) AS TeamTable)) ORDER BY '+ @User_Sort +' Desc'
    END
Else
  IF (@User_Rank = 'Asc')
    BEGIN
      Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Asc'
    END
  Else
    BEGIN
      Set @SQLQuery = 'SELECT TOP '+ STR(@Page_Size) +' Digitaltion_ID FROM [DigitalART_Digitaltion] ORDER BY '+ @User_Sort +' Desc'
    END


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

阅读全文
0 0

相关文章推荐

img
取 消
img