This topic is locked

Sort Last Names

3/9/2009 12:17:19 PM
PHPRunner General questions
vin7102 author

Hi,
In a report page, I need to sort a field called Employee_Name in table (payroll_employee_list)

The problem is that first and last names are in the same field separated by a space and I want the report to sort by last name.

Thanks for the help or ideas in advance.

A
alang 3/9/2009

Suggest you consider creating a calculated field in your SQL (say using MySQL SUBSTRING_INDEX function) to make a last name field which you can then sort by.

Sergey Kornilov admin 3/9/2009

Vince,
I'm afraid it won't work this way.
You need to store first and last names in separate fields. If you need to display them together use concat() function in SQL query i.e.

select

concat(FirstName, ' ', LastName) as FullName,

...

from ...
vin7102 author 3/9/2009

Thanks Guys for your help,

Sergey, Thats what I did and it actually allowed me to fix a couple other problems along the way!!

Thank you..