Solved

Simple SQL question.. URGENT!

Posted on 2006-10-23
4
1,169 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
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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now