1

1 つのストアド プロシージャを使用して、テーブルから最後の N 行を取得したい。

ストアド プロシージャには、and などのパラメータがいくつかあり@PageNumberます@RowCount

私には2つの問題があります:

  • I need to count the rows and results in my user interface because I want to limit my user when he is in last page and press next page.

  • I want my user can press last page when he is in other page.

Tip: I don't want to execute my stored procedure twice to get the results and row count because it creates dynamic and need long time for execution.

For more description I most say that my sp is like :

Create Procedure TestSelectBill  
(  
    @PageNumber int = 1 ,  
    @RowCount int = 5  
)  
As  
Begin  
    Select   
        *  
    From billing.BillMaster As BM  
    Where  
    ( Bm.SubscribeId = '12345674' )  
    Order by SubscribeId  
    OFFSET @PageNumber * @RowCount ROWS  
    FETCH NEXT @RowCount ROWS ONLY;  
End  
4

2 に答える 2

2

Row_Number()クエリで使用してSubscribeId降順で並べ替えることができ、row[0]["RowNumber"]合計数は次のようになります。

Select
        *  ,
ROW_NUMBER() OVER ( ORDER BY SubscribeId DESC) as RowNumber
    From billing.BillMaster As BM  
    Where  
    ( Bm.SubscribeId = '12345674' )  
    Order by SubscribeId  
    OFFSET @PageNumber * @RowCount ROWS  
    FETCH NEXT @RowCount ROWS ONLY;
于 2013-03-09T11:02:51.647 に答える