meixell
asked on
simple Microsoft SQL question.. URGENT
I have a table with a first name and a last name column. What I want is to return only the last name if the first name is null, but (last name + ", " + first name) otherwise.
Any suggestions on how to do this without having to muck with a procedure? MySQL has a CONCAT_WS() (ws = with separator) function that does what I want, but I haven't been able to find any simple equivalent from Microsoft.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or this may work
select lastName + coalesce(firstName & ', ', '') as pName from tableName
select lastName + coalesce(firstName & ', ', '') as pName from tableName
This is a duplicate question that exceeds the maximum 500 allowed. Please post a message in Community Support to have the points reducd in both threads as you have valid comments in both. See here:
https://www.experts-exchange.com/questions/22035147/Simple-SQL-question-URGENT.html
https://www.experts-exchange.com/questions/22035147/Simple-SQL-question-URGENT.html
@meixell, please ask for a refund from CS of your points as this has already been answered in your other link.
ASKER
Yea.. Sorry about the dual post. I didn't think my submission went through the first time.
select lastName & coalesce(firstName & ",", "") from tableName