Do not update data

  • 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?

  • 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

     

     

  • 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.

  • I am not sure

    update telematchout

    set telephone = isnull(areacodet,'') + phonet

    when Telephone is null

     and PHONET is not null

  • Thanks, This worked great.

  • 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