Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005

    Unanswered: set value if null

    I need to update tableA.fieldA with data from tableB.fieldB, but I do not want overwrite tableA.fieldA current data. I only want to add the info to fieldA if it is currently null.

    The primary key in each table is employeeid.

    i know i can do this

    update tableA
    set fieldA = t.fieldB
    from tableA
    inner join tableB as t
    on t.employeeid = tableA.employeeid

    but that will overwrite everthing from tableB to tableA and I only want to update if fieldA is null.


  2. #2
    Join Date
    Nov 2004
    on the wrong server
    Provided Answers: 6
    update A
    set fieldA = t.fieldB
    from tableA A
    inner join tableB as t
    on t.employeeid = A.employeeid
    where A.fieldA is null
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

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