From: artist on
Hi,

I have 2 tables. I have a query that updates the values of some columns
from table A with values from some columns of table B based on a given
condition.

Something like this:

Update T1
Set T1.C1 = T2.C1, T1.C2 = T2.C2, T1.C3 = T2.C3
FROM A T1
INNER JOIN B T2
ON <my condition>

That's simple to do, but I was wondering how I can only update the
columns where the value of the column of table B is NOT NULL.

The reason is because I don't want to overwrite not null values in table
A with a NULL value. In that case I want to leave as it is.

Thanks
From: Tom Cooper on
Update T1
Set C1 = COALESCE(T2.C1, T1.C1), C2 = COALESCE(T2.C2, T1.C2), C3 =
COALESCE(T2.C3, T1.C3)
FROM A T1
INNER JOIN B T2
ON <my condition>

will update only those columns where the corresponding value in B is not
NULL.

Tom

"artist" <nowhere(a)nowhere.com> wrote in message
news:eSvgSkltKHA.3536(a)TK2MSFTNGP06.phx.gbl...
> Hi,
>
> I have 2 tables. I have a query that updates the values of some columns
> from table A with values from some columns of table B based on a given
> condition.
>
> Something like this:
>
> Update T1
> Set T1.C1 = T2.C1, T1.C2 = T2.C2, T1.C3 = T2.C3
> FROM A T1
> INNER JOIN B T2
> ON <my condition>
>
> That's simple to do, but I was wondering how I can only update the columns
> where the value of the column of table B is NOT NULL.
>
> The reason is because I don't want to overwrite not null values in table A
> with a NULL value. In that case I want to leave as it is.
>
> Thanks

From: artist on
Thanks Tom. That's exactly what I need.
 | 
Pages: 1
Prev: Slow response
Next: Need help with the Query.