Link to home
Start Free TrialLog in
Avatar of meixell
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.
 
Avatar of Raynard7
Raynard7

cant you just do

select lastName & coalesce(firstName & ",", "") from tableName
ASKER CERTIFIED SOLUTION
Avatar of sajuks
sajuks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or this may work
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
@meixell, please ask for a refund from CS of your points as this has already been answered in your other link.
Avatar of meixell

ASKER

Yea.. Sorry about the dual post. I didn't think my submission went through the first time.