locked
Coalesce/ nested? how? RRS feed

  • Question

  • Hello team,

    I want coalesce function brings the value of field 2 if the value of field 1 is null.

    If address1 in fieldAddress1 is null bring address2 from fieldAddress2.

    How should I use it?

    Regards,

    CloudsInSky.


    CloudsInSky

    Friday, July 6, 2018 2:43 AM

Answers

  • Hello team,

    I want coalesce function brings the value of field 2 if the value of field 1 is null.

    If address1 in fieldAddress1 is null bring address2 from fieldAddress2.

    How should I use it?

    Regards,

    CloudsInSky.


    CloudsInSky

    Hi CloudsInSky,

    You could write the statement like this.

    SELECT Coalesce(fieldAddress1,fieldAddress2) FROM Your_Table

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 6, 2018 2:59 AM
  • SELECT Coalesce(fieldAddress1,fieldAddress2) ...
    SELECT ISNULL(fieldAddress1,fieldAddress2) ...
    SELECT CASE when fieldAddress1 is null then fieldAddress2 else fieldAddress1 End ...

    • Marked as answer by cloudsInSky Monday, July 9, 2018 3:08 AM
    Friday, July 6, 2018 1:44 PM

All replies

  • Hello team,

    I want coalesce function brings the value of field 2 if the value of field 1 is null.

    If address1 in fieldAddress1 is null bring address2 from fieldAddress2.

    How should I use it?

    Regards,

    CloudsInSky.


    CloudsInSky

    Hi CloudsInSky,

    You could write the statement like this.

    SELECT Coalesce(fieldAddress1,fieldAddress2) FROM Your_Table

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 6, 2018 2:59 AM
  • SELECT Coalesce(fieldAddress1,fieldAddress2) ...
    SELECT ISNULL(fieldAddress1,fieldAddress2) ...
    SELECT CASE when fieldAddress1 is null then fieldAddress2 else fieldAddress1 End ...

    • Marked as answer by cloudsInSky Monday, July 9, 2018 3:08 AM
    Friday, July 6, 2018 1:44 PM
  • where's nesting needed here?

    All you need is a simple COALESCE

    COALESCE(fieldAddress1,fieldAddress2)

    if fieldAddress2 can be null and there is another field calles fieldAddress3 which can be used you can add it like this

    COALESCE(fieldAddress1,fieldAddress2,fieldAddress3)

    so there's no need of nesting


    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    Friday, July 6, 2018 2:00 PM