How to check Previous and next record values?

  • Hi all,

    I wanted to check the previous and next record values.

    For example:

    sKey NextKey PreviousKey

    1 2 Null

    2 8 1

    8 5 2

    5 null 8

    Ex : In the first record of the table, the NextKey is pointing to 2.

    So the next record of Skey will be 2. The Next Key for this record is 8. Like wise the next record of this should have the Skey as 8.

    Now I need to check whether the NextKey and SKey are correct for all rows.

    For that I need to check the previous record of "Next key" and next record of "Skey".

    Any idea?

    Regards

    Helen

  • Hi

    I hope this is right... did little bit of testing and seems allright.

    To find out the wrong previous key entry..

    select n.* From table1 n,table2 t

    where n.previouskey = t.skey

    and t.nextkey <> n.skey.

    To find out the wrong next key entry....

    select n.* From table1 ntable1 t

    where t.pkey = n.skey

    and n.nkey <> t.skey

    "Keep Trying"

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply