Results 1 to 7 of 7

Thread: Union

  1. #1
    Join Date
    Jun 2003
    Posts
    294

    Unanswered: Union

    I wanna make a union of 2 cursors.

    How do i do It ?



    Something like this:


    Peter 20 (564)654464 US <= From Cursor 1
    Dave 30 (464)654646 UK <= From Cursor 2

    Is there an easy way to do it?

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

    Re: Union

    No, there isn't an easy way, but why would you want to? Why not have one cursor based on the union of the two queries?

    A union takes the results of 2 queries and merges them so that all the distinct row values from both queries appear once only. To simulate that using two cursors you would have to:
    Code:
    1) ensure that both cursor order data by the key values
    2) open both cursors
    3) fetch from cursor1
    4) fetch from cursor2
    5) if cursor1_row.key < cursor2_row.key then
          output cursor1_row
          fetch from cursor1
        elsif cursor1_row.key > cursor2_row.key then
          output cursor2_row
          fetch from cursor2
        else
          output cursor1_row
          fetch from cursor1
          fetch from cursor2
        end if
    6) Go to 5
    I have left out handling the cursor %NOTFOUND condition.

  3. #3
    Join Date
    Nov 2003
    Location
    down on the cube farm, left then right then another left
    Posts
    467
    What andrewst said. I would add however that a union does not need to return "all the distinct row values from both queries". That behavior can be changed.

  4. #4
    Join Date
    Jun 2003
    Posts
    294

    Re: Union

    The problem is that I take, both Cursors from diferent Out procedure parameters, so I never use the original Queries, and now I need the cursos together, in only one Cursor, they both have the same structure (type)

  5. #5
    Join Date
    Nov 2003
    Location
    down on the cube farm, left then right then another left
    Posts
    467
    Can you send the outputs of the original cursors to a temp file and then query the temp file? Not real elegant but would do the trick.

  6. #6
    Join Date
    Jun 2003
    Posts
    294

    Unhappy

    I can't user any file !!

  7. #7
    Join Date
    Nov 2003
    Location
    down on the cube farm, left then right then another left
    Posts
    467
    Are you saying the requirements to do allow you to use a file or no one has given you the privileges/authority to use a file?

    you said " I take both Cursors from diferent Out procedure parameters, so I never use the original Queries". Do you mean "both cursors" or "the results from both cursors" come from different OUT parameters. By this I mean that you call procedure1 and it "returns" all the values from cursor1 and you call procedure2 and it returns all the values from cursor2?

Posting Permissions

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