Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    83

    Thumbs down Unanswered: MERGE INTO statement

    Could you please tell me the sybase equivalent for Oracle's MERGE INTO statement

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    What does the MERGE INTO statement do?

  3. #3
    Join Date
    Mar 2007
    Posts
    25

    Merge statement

    Hi pdreyer,

    A merge statement does the following.

    *Provides the ability to conditionally update or insert data into a database table

    *Performs an UPDATE if the row exists, and an INSERT if it is a new row:
    – Avoids separate updates
    – Increases performance and ease of use
    – Is useful in data warehousing applications

    In case of sybase I think we need to make use of IF EXISTS to check whether the row exists if yes we need to update else insert.

    Regards,
    Poornima
    Last edited by J.Poornima; 03-19-07 at 08:25.

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Yes, you'll have to break it up into individual statements so that this
    Code:
    MERGE INTO bonuses B
    USING (
      SELECT employee_id, salary
      FROM employee
      WHERE dept_no =20) E
    ON (B.employee_id = E.employee_id)
    WHEN MATCHED THEN
      UPDATE SET B.bonus = D.bonus + E.salary * 0.1
      DELETE WHERE (S.salary>=100000)
    WHEN NOT MATCHED THEN
      INSERT (B.employee_id, B.bonus)
      VALUES (E.employee_id, E.salary * 0.05);
    Become
    Code:
    delete bonuses 
    from bonuses b,employee e
    WHERE b.employee_id = e.employee_id
      and e.dept_no=20
      and e.salary>=100000
    
    update bonuses 
    set bonus = bonus + e.salary * 0.1
    from bonuses b,employee e
    WHERE b.employee_id = e.employee_id
      and e.dept_no=20
    
    insert into bonuses (employee_id, bonus)
    select employee_id, salary * 0.05
    from employee e
    where e.dept_no=20
      and salary<100000
      and not exists 
           (select 1 from bonuses b
            where b.employee_id = e.employee_id)

Posting Permissions

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