Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL for update

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-06 : 08:37:05
Hari writes "I want to update a column that is having NULL values. Value for this column is obtained from another table. I would like to update this coulmn only if the returned value is non NULL. If the returned value is NULL, I don't want to update NULL column again with a NULL. What will be the SQL for this.

update person a
set a.age=(SELECT b.age FROM person_age b WHERE a.id = b.id)
where a.age is null

This SQL will update person even if the return value is NULL."

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-06 : 08:39:15
will this do?
update person a
set a.age=(SELECT b.age FROM person_age b WHERE a.id = b.id and b.age is not null)
where a.age is null

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -