470,643 Members | 1,371 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

Grouping columns

Hi,

I was trying to retrieve some data in such a way that it 2 columns will
be merged into one, with a column in between. I am trying to do
something like this:

SELECT LastName + ", " + FirstName AS Name
FROM EmployeeTBL
ORDER BY LastName

But SQL Server does not like this syntax (though it does work with
"LastName + FirstName").

I appreciate any help.

Thanks,
Aaron

Jul 23 '05 #1
4 1064
SQL Server uses single quotes for strings, not double quotes. Also...
you probably want to order by the first name if the last name is the
same, correct? Try:

SELECT LastName + ', ' + FirstName AS Name
FROM EmployeeTBL
ORDER BY LastName, FirstName

If it is possible for there to be NULL values or empty strings in
either of the columns then you will need to account for that as well.

HTH,
-Tom.

Jul 23 '05 #2
SELECT LastName + ", " + FirstName AS Name
FROM EmployeeTBL
ORDER BY Name

This should work.

Jul 23 '05 #3
Use single qutes instead of double:

SELECT LastName + ', ' + FirstName AS Name
FROM EmployeeTBL
ORDER BY LastName

Jul 23 '05 #4
Hmm, I didn't notice the double quotes ealier.

SELECT LastName + ', ' + FirstName AS Name
FROM EmployeeTBL
ORDER BY Name

You can always use the final column name in the ORDER BY condition.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Debbie Davis | last post: by
3 posts views Thread by Kevin Brown | last post: by
1 post views Thread by teddysnips | last post: by
10 posts views Thread by Mat | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.