Declare @user_condition varchar (500) Declare @user_sort varchar (20) Declare @user_rank varchar (4)
Declare @Page_Size RealDeclare @Page_Order INTDECLARE @SqlQuery Varchar (1000)
Set @Page_size = 10set @PAGE_ORDER = 1
Set @user_sort = 'DIGITATION_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 'ENDElse 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) ' DIGITATION_ID From [DIGITALART_DIGITALTION] ORDER BY ' @User_sort ' desc 'endselect @page_size as page_size, @page_order as page_orderselect @SqlQueryexecute (@sqlQuery) GO