Get the full name

  • TomThomson - Wednesday, January 25, 2017 11:28 AM

    Julie Breutzmann - Wednesday, January 25, 2017 10:05 AM

    I've corrected the typos. But my question still remains. This seems much simpler than the other options.
    SELECT COALESCE(firstname + ' ', '') + COALESCE( SUBSTRING(middlename,1, 1) + '. ','') + lastname + COALESCE(', ' + suffix,'')
    FROM dbo.Fullname

    Yes, at least two reasons.
    The killer is that the row (NULL ,     'Ryan'     , 'Lucas' , 'M.D.') should produce 'R. Lucas' but your code produces 'R. Lucas, M.D.'
    The other reason is that a row where middlename and firstname are both NULL should not return the suffix, but your code will - perhaps that's less of a killer because the sample data provided doesn't include such a row, but perhaps not since the specification is very clear.

    Ok, I understand. Thanks!

Viewing post 16 (of 15 total)

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