Click here to Skip to main content
15,888,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi In my asp.net application
I want to sort employees based on their code

code is

emp 1000
emp 23
emp 33


i want result in this order

emp23
emp33
emp1000


pls help me
Posted
Updated 11-Aug-11 0:51am
v2
Comments
Om Prakash Pant 11-Aug-11 6:25am    
emp code and id stored in separate columns or in single column?
Praveen Kullu 11-Aug-11 9:12am    
Please see my updated solution .

try in this way

DECLARE @Table TABLE (ID VARCHAR(30))

INSERT @Table
SELECT 'emp1000' UNION ALL
SELECT 'emp23' UNION ALL
SELECT 'emp33' 


SELECT ID
FROM @Table
ORDER BY SPACE(50 - LEN(ID))+ ID ASC
 
Share this answer
 
You store only Integer value in DB. while querying use the below way
SQL
SELECT ID, 'emp'+ID AS EmpID FROM TableName ORDER BY ID
 
Share this answer
 
It seems that "emp" is common for all records.
If that the case,
you can trim "emp" from all rows,
then store all records in an ArrayList,
then Sort that ArrayList,
and finally display all objects from ArrayList by appending "emp" to it.
 
Share this answer
 
Seems like you want to trim spaces.
You can use String.Trim method.

Refer this link
http://msdn.microsoft.com/en-us/library/system.string.trim.aspx[^]
 
Share this answer
 
Comments
Shibiny 11-Aug-11 6:29am    
no. i mean that, i want to sort based on last numbers .
I believe you don't have a table where there are repeating values (i.e emp) in a column. If the employee name and code is in one column (like emp100,emp23,emp33) ,
SQL
select employeename from tablename order by len(employeename), employeename asc
 
Share this answer
 
v4
Comments
nagendrathecoder 11-Aug-11 7:03am    
i guess this won't do rightly.....it will consider emp230 before emp34.
Praveen Kullu 11-Aug-11 9:09am    
Please check my updated solution , this one works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900