Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Row_Number with union

Author  Topic 

AJA
Starting Member

3 Posts

Posted - 2009-08-18 : 09:03:36
Hi,

I have to implement paging in my application and my SP fetches data for 2 different entities in same query using union which is my application requirement.

ex. @Start,@end,@reccount
with cte(Rownum,a,b)
as
(select Row_Number() Over (Order by x.a).x.*
from
(select top(@reccount),a,b from table1
union all
select top(@reccount),a,b from table2)
x)

select * from cte where rownum between @start and @end

So in this way my call become very costly. i am trying to tune it further.

Please suggest if i can do better in case.

Thanks in advance.

I wish, I wasn't so nice

I wish, I wasn't so nice !
   

- Advertisement -