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