Best way of concatenating values and returning an empty for null values

  • I've taken an online practice exam for my 70-461 exam and I cannot work out why concatenating using '+' is better than using the concatenating function:

    Thanks
    J

  • It's not the + vs concat but 
    Answer A does what's being asked only when AddressLine1 and Region fields aren't NULL so it doesn't really do what is asked either. Of the 4 answers it at least tests addessLint2 for NULL, whereas D doesn't return the AddressLine1, AddressLine2 and Region fields separated by carriage returns testing for NULL and replacing it with an empty string anywhere. You could write a query that returns the AddressLine1, AddressLine2 and Region fields using the Conat function that replaces any NULL values with empty strings.
  • Joe Torre - Tuesday, March 20, 2018 4:11 PM

    It's not the + vs concat but 
    Answer A does what's being asked only when AddressLine1 and Region fields aren't NULL so it doesn't really do what is asked either. Of the 4 answers it at least tests addessLint2 for NULL, whereas D doesn't return the AddressLine1, AddressLine2 and Region fields separated by carriage returns testing for NULL and replacing it with an empty string anywhere. You could write a query that returns the AddressLine1, AddressLine2 and Region fields using the Conat function that replaces any NULL values with empty strings.

    I think you are right and I would guess you got caught by the same thing I did thinking A is conditionally correct. A does return what's needed - I had to go back and read the table definition. AddressLine2 is the only one that is nullable. So AddressLine1 and Region are not nullable. AddressLine2 is the one needing to be checked for null.

    Sue

  • Joe Torre - Tuesday, March 20, 2018 4:11 PM

    It's not the + vs concat but 
    Answer A does what's being asked only when AddressLine1 and Region fields aren't NULL so it doesn't really do what is asked either. Of the 4 answers it at least tests addessLint2 for NULL, whereas D doesn't return the AddressLine1, AddressLine2 and Region fields separated by carriage returns testing for NULL and replacing it with an empty string anywhere. You could write a query that returns the AddressLine1, AddressLine2 and Region fields using the Conat function that replaces any NULL values with empty strings.

    Thanks Joe.

    Yes I missed the Address2 element of it. The old adage of RTFQ applies I think 😀

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply