Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting non-null values 1

Status
Not open for further replies.

Azathoth

Technical User
Jul 14, 2003
61
US
Is it possible to select all non-null values from a table row and update another table row with them? For example, the table before the statement is run:

Id Val1 Val2 Val3
1 3 4 1
2 NULL NULL 5

And after:

Id Val1 Val2 Val3
1 3 4 5
2 NULL NULL 5

The number of columns containing null is unknown. Any help would be appreciated.
 

I looked this post for a few minutes, I don't think I can find a way to understand the requirement. I guess this is the toughest part. Give us an example and for sure we can do it!
 
Technically possible:
Code:
update A
set 	Val1 = isnull(B.Val1, A.Val1),
	Val2 = isnull(B.Val2, A.Val2),
	Val3 = isnull(B.Val3, A.Val3)
from blah A
cross join blah B
where A.id = 1 and B.id = 2
... though I'd be probably concerned about inevitable dummy updates in some situations.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top