Question : SQL Server 2005 paging and UNION

Hi,

I have am using a sql server 2005 to paginate.

Everything works fine, however I have a second table that I need to add to the query as a UNION.

The second table is called ref_donor_new.

The table ref_donor_new has the exact same column definition as ref_donor.

I appreciate any advise on this. Thank you in advance.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
ALTER PROCEDURE [dbo].[get_data] (
 @rowsPerPage int,
 @pageNum int

)
AS
BEGIN
    
WITH sqlpaging
AS
(
SELECT TOP(@rowsPerPage * @pageNum) ROW_NUMBER() OVER (ORDER BY UPPER(formal_name)) as resultNum

, rd.id
, fss.id AS status_table_record_id
, fss.status
, UPPER(formal_name) AS formal_name
, sis_code
, prog
, ISNULL(chartfield,'') AS chartfield
FROM ref_donor rd
LEFT JOIN fundraising_scholarship_status fss ON rd.id = fss.scholarship_id
)
SELECT * FROM sqlpaging WHERE resultNum > ((@pageNum - 1) * @rowsPerPage)  


END;

Answer : SQL Server 2005 paging and UNION

oops, typo
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
WITH CTE
AS
(
SELECT 
rd.id
, fss.id AS status_table_record_id
, fss.status
, UPPER(formal_name) AS formal_name
, sis_code
, prog
, ISNULL(chartfield,'') AS chartfield
FROM ref_donor rd
LEFT JOIN fundraising_scholarship_status fss ON rd.id = fss.scholarship_id
union -- or union all depending on your requirements
select ....same number of columns ... from ref_donor_new
), sqlpaging as (
select TOP(@rowsPerPage * @pageNum) ROW_NUMBER() OVER (ORDER BY formal_name) as resultNum, *
from CTE 
)
SELECT * FROM sqlpaging WHERE resultNum > ((@pageNum - 1) * @rowsPerPage)
Random Solutions  
 
programming4us programming4us