Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ORDER BY

Author  Topic 

pnunes1
Starting Member

2 Posts

Posted - 2006-01-06 : 12:09:54
I have string fields witch is people names.
I want to order by last name (surname).
The question is that I only have one field with full names. How can I order a query by last name ?

Example:
Pedro Alexandre Nunes
João Antunes
António Camargo Setubal

Desired order:

Antunes, João
Nunes, Pedro Alexandre
Setubal, António Camargo


Thanks.

nr
SQLTeam MVY

12543 Posts

Posted - 2006-01-06 : 12:35:02
order by right(name, charindex(' ', reverse(name))


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pnunes1
Starting Member

2 Posts

Posted - 2006-01-07 : 05:50:41
Solved.

Thank you.
Go to Top of Page
   

- Advertisement -