Solved

simple Microsoft SQL question..   URGENT

Posted on 2006-10-23
8
1,061 Views
Last Modified: 2008-02-01

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.
 
0
Comment
Question by:meixell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17793278
cant you just do

select lastName & coalesce(firstName & ",", "") from tableName
0
 
LVL 33

Accepted Solution

by:
sajuks earned 20 total points
ID: 17793288
something like ...
SELECT
    CASE WHEN fname IS Null and lname is not null then rtrim(lname)
    WHEN fname IS not Null and lname is null then rtrim(fname)
    ELSE rtrim(lname) +','+rtrim(fname)
end
FROM mytable
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17793359
or this may work
select lastName + coalesce(firstName & ', ', '') as pName from tableName
0
Upcoming Webinar: Securing your MySQL/MariaDB data

Join Percona’s Chief Evangelist, Colin Charles as he presents Securing your MySQL®/MariaDB® data on Tuesday, July 11, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17793368
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:
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_22035147.html
0
 
LVL 33

Expert Comment

by:sajuks
ID: 17801850
@meixell, please ask for a refund from CS of your points as this has already been answered in your other link.
0
 

Author Comment

by:meixell
ID: 17802154
Yea.. Sorry about the dual post. I didn't think my submission went through the first time.


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question