sql insert

  • Hi All,

    We have a table which has columns empid,plan,physid. We updated table with new plan

    here is an example:empid plan physid

    1 a null

    1 b 20

    1 c 20

    How to insert physid for plan a? The query should be like when ever an employee has physid for planb and planc then his plan a should also have the same physid rather than null.There are almost 10000 employees who changed to plan a

    and some of them are showing null . So can we insert physid for plan a by comparing with plan b and planc? We only need to update those values which are only showing nulls.

  • Assuming the empid is the unique key, you can use a self join from plan A table and in your where clause specify that you're looking for nulls. Where ever there is a null found, you just update that value found in the other joined record in plan A.

    You do not need an insert for this as you already have the data.

    --
    :hehe:

  • read about UPDATE in books online.

  • Similar problem:

    http://www.sqlservercentral.com/Forums/Topic775170-149-1.aspx

    The solution posted there will work for you too with some minor changes.

    HTH,

    Sups

  • Thanks a lot , It works !

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

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