Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Formatting person's name

$
0
0

I have a table with a persons firstname, and lastname. And neither one are required fields. I inherited this database so I don't agree with the structure but I have to deal with it..

Anyways I need to pull a list with the persons name formatted as such "LastName, FirstName", delimited by a comma.

If no Last name & first Name exists, then just use LastName, if no lastname just use First name. If none exist use NULL. I know how to use COALESCE in this instance the problem is the 1st part when I attempt to concatenate the Last and First together with a comma in the 1st parameter of the COALESECE statement it will never be null and will always display "," if no first and last name exist. How can I make this work so that if nothing exists display null and follow the rules I just stated above?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>