views:

128

answers:

1

I've been trying to solve this problem for a few days now without much luck. I have found loads of resources that talk about paging on SQL Server 2000 both here and on codeproject.

The problem I am facing is trying to implement some sort of paging mechanism on a table which has three keys which make up the primary key. Operator, CustomerIdentifier, DateDisconnected.

Any help/pointers would be greately appreciated

+1  A: 

SQL Server 2000 doesn't have the handy row_number function, so you'll have to auto-generate a row number column with a subquery, like so:

select
    *
from
    (select
        *,
        (select count(*) from tblA where 
            operator < a.operator
            or (operator = a.operator
                and customeridentifier < a.customeridentifier)
            or (operator = a.operator
                and customeridentifier = a.customeridentifier
                and datedisconnected <= a.datedisconnected)) as rownum
     from
        tblA a) s
where
    s.rownum between 5 and 10
order by s.rownum

However, you can sort those rows by any column in the table -- it doesn't have to use the composite key. It would probably run faster, too!

Additionally, composite keys are usually a flag. Is there any particular reason you aren't just using a surrogate key with a unique constraint on these three columns?

Eric
Thank you for your reply - I will try this out now. What do you mean composite keys are usually used as flags? The database is pretty old, we didn't design it and it's using that structure which I think we are tied to, until we develop a new version.
Malachi
when I subsitute my table names into that query you provided I am getting an error on the as rownum line "Msg 156, Level 15, State 1, Line 12Incorrect syntax near the keyword 'as'." any suggestions?
Malachi
Forgot a paren. Fixing now.
Eric