Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple SQL question.. URGENT!

Posted on 2006-10-23
4
Medium Priority
?
1,179 Views
Last Modified: 2012-06-27

 
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
4 Comments
 
LVL 26

Expert Comment

by:DireOrbAnt
ID: 17793339
SELECT LastName + ISNULL(', ' + FirstName, '') As Name
FROM ...
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17793369
This is a duplicate question that exceeds the maximum 500 allowed. Please post a message in Community Support to have the points reduced in both threads as you have valid comments in both.  See here:
http://www.experts-exchange.com/Databases/Q_22035145.html
0
 
LVL 33

Accepted Solution

by:
sajuks earned 2000 total points
ID: 17793996
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

636 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