May 26, 2009 at 4:06 am
Is it Possible to get total count and Paginated Records using cte only with out subquery?
Example:-
with cte as (select *,Row_number() over(order by id) from TableName)
select *,(select count (*) from cte) from cte where rownumber between some integers
I need other better queries than this.
May 26, 2009 at 5:14 am
with cte as (select *,Row_number() over(order by id) as rownumber,
count(*) over() as total from TableName)
select * from cte where rownumber between some integers
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537May 26, 2009 at 7:13 am
hi, U sent
with cte as (select *,Row_number() over(order by id) as rownumber,
count(*) over() as total from TableName)
select * from cte where rownumber between some integers
ok its good,but for every row of cte,count wil b repeated.
Do u think its better than what i have sent? If so can u pls explain
Thanks in advance:-)
May 26, 2009 at 7:40 am
Suggest you try both approaches, in my experience "count(*) over()" doesn't perform particularly well.
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537May 26, 2009 at 10:53 pm
Hi,
I saw in Profiler,ur query wil perform poorly than my query.Urs wil take
twice as much as reads and cpu and duration of my query.
Any way thanks for replying.:-)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply