August 26, 2009 at 4:12 pm
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.
August 27, 2009 at 7:03 am
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:
August 27, 2009 at 8:35 am
read about UPDATE in books online.
August 27, 2009 at 9:39 am
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
August 27, 2009 at 11:46 am
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