July 16, 2007 at 8:54 am
I have the following update query:
Update
TELEMATCHOUT
Set Telephone = CASE WHEN PHONET = ''
THEN NULL
ELSE AreacodeT+PhoneT
ENd
My issue is I need to keep the existing data in Telephone if it already exists or if PhoneT is null. Right now is putting NULL values into TELEPHONE where data actually pre-existed.
Any ideas?
July 16, 2007 at 9:29 am
Hi Arthur!
What dou you think about this one?
If Telephone is null or PHONET is not null
Begin
Update TELEMATCHOUT
Set Telephone = AreacodeT+PhoneT
End
July 16, 2007 at 9:32 am
Try:
update
telematchout set telephone = case when telephone is null then coalesce(areacodet,'') + coalesce(phonet,'') else telephone end
Now if telephone is not null it simply uses the current value of telephone as the update value. The way you worded the problem you are really only concerned when there is data in telephone otherwise perform the update. I added the coalesce to each of the other values to inusre that if ether is null you get at least one of the values.
James.
July 16, 2007 at 9:50 am
I am not sure
update telematchout
set telephone = isnull(areacodet,'') + phonet
when Telephone is null
and PHONET is not null
July 16, 2007 at 12:51 pm
Thanks, This worked great.
July 16, 2007 at 12:55 pm
Your welcome, and thanks for the feedback.
James.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply