开发者

modify table with column with null values

what if I wanted to update the records in the table by altering values in one of the columns?

I have records in the table that have one column empty(null values). I want to change these values and i开发者_StackOverflownsert values from another table into those records.

Basically I have a table with one column empty. I do not want to append to the end of the table but start inserting from record 1.


For the existing records, you would have to use UPDATE to update that one column, WHERE thatColumn IS NULL.

Shouldn't the values in that column have some relation to the rest of the record? I could understand initializing the existing records to a non-null value, or using an UPDATE query to populate data from another table in that column, but all related to the original row...

UPDATE old SET old.badColumn = new.newData
FROM oldTable old 
JOIN newTable new on old.someID = new.someID

This would find the related data in newTable matching oldTable, and update the badColumn to some data from newTable... let me know if you need more help.


See the "Using the UPDATE statement with information from another table" section from this page of SQL Server Books Online.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜