, , , :
- :
...
, @Count int OUTPUT
AS
Select @Count = (
Select Count(*)
From comments
Where comments.postid = @postid
And Col1 = ... And Col2 = ...
)
With NumberedResults As
(
Select ...
, ROW_NUMBER() OVER( ORDER BY dateposted ASC ) As Num
From comments
Where Col1 = ... And Col2 = ...
)
Select ...
From NumberedResults
Where Num Between ( @PageIndex - 1 ) * @PageSize + 1 and @PageIndex * @PageSize
, , .
. -. , . , .
With NumberedResults As
(
Select ...
, ROW_NUMBER() OVER( ORDER BY dateposted ASC ) As Num
From comments
Where Col1 = ... And Col2 = ...
)
Select ...
, ( Select Count(*) From NumberedResults ) As TotalCount
From NumberedResults
Where Num Between ( @PageIndex - 1 ) * @PageSize + 1 and @PageIndex * @PageSize
- , temp
...
, @TotalCount int OUTPUT
AS
Declare @PagedResults Table (
Col1 ...
, ...
, TotalCount int
)
With NumberedResults As
(
Select ...
, ROW_NUMBER() OVER( ORDER BY dateposted ASC ) As Num
From comments
)
Insert @PagedResults( Col1...., TotalCount )
Select ...
, ( Select Count(*) From NumberedResults ) As TotalCount
From NumberedResults
Where Num Between ( @PageIndex - 1 ) * @PageSize + 1 and @PageIndex * @PageSize
Set @TotalCount = ( Select TOP 1 TotalCount From @PagedResults )
Select ...
From @PagedResults