Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    66

    Unanswered: If - Then - Else Loop

    Hi,

    I've 3 arrays RANK,CONFDATE,ROWID. They are not in sorted order.
    For a partcular ID = 200 , there are 3 records in the array :

    1.
    RANK(1) = 3 , CONFDATE(1)=03-MAR-2003 , ROWID(1) =BB
    RANK(2) = 1 , CONFDATE(2)=04-MAR-2003 , ROWID(2) =AA
    RANK(3) = 2 , CONFDATE(3)=09-MAR-2003 , ROWID(3) =CC

    The output should be
    RANK(1) = 3 , CONFDATE(1)=03-MAR-2003 , ROWID(1) =BB

    2.
    RANK(1) = 1 , CONFDATE(1)=03-MAR-2003 , ROWID(1) =BB
    RANK(2) = 1 , CONFDATE(2)=04-MAR-2003 , ROWID(2) =AA
    RANK(3) = 1 , CONFDATE(3)=09-MAR-2003 , ROWID(3) =CC

    The output should be
    RANK(3) = 1 , CONFDATE(3)=09-MAR-2003 , ROWID(3) =CC

    3.
    RANK(1) = 1 , CONFDATE(1)=03-MAR-2003 , ROWID(1) =BB
    RANK(2) = 1 , CONFDATE(2)=03-MAR-2003 , ROWID(2) =AA
    RANK(3) = 1 , CONFDATE(3)=03-MAR-2003 , ROWID(3) =CC

    The output should be
    RANK(2) = 1 , CONFDATE(2)=03-MAR-2003 , ROWID(2) =AA

    assume AA is the max ROWID in the array.

    Give higher priority to RANK , then CONFDATE and then ROWID

    I need a simple IF - THEN - ELSE loop to implement the logic.

    Any help will highly appreciated ...
    Thanks ..
    himridul

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: If - Then - Else Loop

    All you need is to loop through the rows, and keep track of the best found so far:
    PHP Code:
    declare
      -- 
    Assume first row is best
      v_bestrow integer 
    := 1;
    begin
      
    for i in 2..3 loop
        
    if rank(i) > rank(v_bestrow
        or (
    rank(i) = rank(v_bestrow) and confdate(i) > confdate(v_bestrow))
        or (
    rank(i) = rank(v_bestrow) and confdate(i) = confdate(v_bestrow) and rowid(i) > rowid(v_bestrow))
        
    then
          v_bestrow 
    := i;
       
    end if;
    end

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •