Question

For displaying the total page number count I need also to retrieve total number of results at the below query. How can I do that ?

Thank you

select 
    AvgLevel, TotalCount, PokemonId, Type1, Speed, MonsterTotalStats 
from 
   (select 
       row_number() over (order by tblPokedex.PokemonId asc) rowNumber,
       AvgLevel, TotalCount, tblPokedex.PokemonId, 
       Type1, tblPokedex.Speed, MonsterTotalStats
    from 
       tblPokemonStats, tblAvailablePokemons, tblPokedex 
    left join 
       tblUsersPokemons on tblPokedex.PokemonId = tblUsersPokemons.PokemonId  
    where 
       tblPokemonStats.PokemonId = tblPokedex.PokemonId 
       and tblPokedex.Class = 'emissary' 
    group by 
       tblPokedex.PokemonId, tblPokedex.Type1, tblPokedex.Speed, 
       tblPokemonStats.AvgLevel, tblPokemonStats.TotalCount, MonsterTotalStats 
   ) result 
where 
    result.rowNumber > 0 and result.rowNumber < 101
Was it helpful?

Solution

Just add column Count(*) over():

..... 
select row_number() 
over (order by tblPokedex.PokemonId asc) rowNumber,
AvgLevel,
Count(*) over() as TotalCount,
.......

see example

select 
AvgLevel,TotalCount,PokemonId,Type1,Speed,MonsterTotalStats, TOTALRECORDCOUNT
from (
select row_number() 
over (order by tblPokedex.PokemonId asc) rowNumber,AvgLevel,TotalCount,tblPokedex.PokemonId,Type1,tblPokedex.Speed,MonsterTotalStats,
count(*) over() as TOTALRECORDCOUNT
from tblPokemonStats,tblAvailablePokemons,tblPokedex left join tblUsersPokemons on tblPokedex.PokemonId=tblUsersPokemons.PokemonId  
where tblPokemonStats.PokemonId=tblPokedex.PokemonId and tblPokedex.Class='emissary' 
group by tblPokedex.PokemonId,tblPokedex.Type1,tblPokedex.Speed,tblPokemonStats.AvgLevel,tblPokemonStats.TotalCount,MonsterTotalStats 
)  
result where result.rowNumber>0 and result.rowNumber<101

OTHER TIPS

You coud use :

SELECT @@ROWCOUNT

check it out here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top