Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006
    Posts
    17

    Unanswered: Update statement

    Hi

    I have two tables with the followinf data.

    Employee1

    EmpoyeeNo Name Role salary
    111 John SSE 112220
    222 rahim SE NULL
    333 RAN DEV 583930


    Employee2
    EmpoyeeNo Name Role salary
    111 John DBA 112220
    222 rahim SEE 353664
    333 RAN DEV 583930
    444 rohit ADM 248299

    I want to update Employee2 from Employee1. If any input column value has null value, then i don't want to updated that column (i.e keep the value as it is). If input value has not null, then i will updated that colum.

    Now my final table (i.e Employee2) will looks like this after updation.

    Employee2
    EmpoyeeNo Name Role salary
    111 John SSE 112220
    222 rahim SE 353664
    333 RAN DEV 583930
    444 rohit ADM 248299

    Please let me know the SQL for this updatation.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    UPDATE employee2
    SET    salary = e1.salary
    FROM   employee2 e2
     INNER
      JOIN employee1 e1
        ON e1.employee_no = e2.employee_no
    WHERE  e2.salary IS NULL
    BTW, I believe you put your NULL salary in the wrong table in your sample data above.
    George
    Home | Blog

Posting Permissions

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