Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    2

    Unhappy Unanswered: Recursive SQL DB2/AS400

    Hi,

    I have problems with this sql statement.


    Table = emaila01
    colum
    evname enname
    AAA--------BBB
    AAA--------CCC
    AAA--------DDD
    CCC--------EEE
    DDD--------FFF


    sqlstring3 = "with temp (enname) as " _
    & "(select distinct evname " _
    & "from emaila01 " _
    & "where evname = 'AAA' " _
    & "union all " _
    & "select c.enname" _
    & "from emaila01 c, temp p " _
    & "where p.enname = c.evname) " _
    & "select distinct enname from temp"


    The answer must be

    BBB
    CCC
    DDD
    EEE
    FFF


    What is wrong?

    Reinhard
    Last edited by ReinhardN; 07-19-04 at 04:52.

  2. #2
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    It's an infinite loop, no? You get ('DDD','AAA'), then 'AAA','DDD' which re-matches 'DDD','AAA'... forever.
    --
    Jonathan Petruk
    DB2 Database Consultant

  3. #3
    Join Date
    Jul 2004
    Posts
    2
    Hi,

    why the DBS/AS400 have not a statement for the recursive sql-select?

    In ORACLE SQL I have the "connect by prior" statement.


    greetings

    ReinhardN

Posting Permissions

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