update query...

  • Hi all: I'm stuck with a problem. I have a table with 2 cloumns say 'A' and 'B'. I have to update the values of 'B' with the corresponding 'A' value whenever 'B' is 'null'. How do i write it in a single update statement? How do I refer the value of the corresponding 'A' that is satisfying the 'where' condition.

    update <table> set B=<'A' value of corresponding record> where B is null

  • Unless I'm misunderstanding...

    Update tbl set B=A where B IS NULL

    tbl Before

    AB
    1a
    2NULL
    3NULL
    4d

    tbl After

    AB
    1a
    22
    33
    4d

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • thanx bud: thats wat i had in mind too. but wanted to confirm it b4 updating it on the live database. i think i shld have a backup in future.

  • I think you should get a dev/playground database where you can try stuff out before running on live.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Quote:

    i think i shld have a backup in future.

    I think you should have a backup NOW!

    -SQLBill

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply