Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi i am currently doing a project in which the database needs to sort the lot numbers
prefix is nvarchar
lotnum is int
suffix is nvarchar

i have managed to convert the lot number
code i used is
SQL
Select (case when prefix is null then '' else prefix end) +
CONVERT ( nvarchar , ( lotnumber ) ) +(case when suffix is null then '' else suffix end)

(values in the database are a1a,1a,1,2,100)
when i order by lotnumber i get
a1a
1a
1
2
100

then prefix to the order by
and get this result
1
a1a
1a
2
100


i have added the suffix as well and returns the same result

i need to order it as follows

1
1a
2
100
a1a


Please could someone help me on this
Posted
Updated 26-Jul-12 23:57pm
v2
Comments
Kenneth Haugland 27-Jul-12 5:53am    
I think youll have to write a custom sort for that. And I would sort the numbers in the DAtaGrid ListView etc insted of the SQL server, and I assume that you mean the same?

HEre are two examples for you:

Dealing with DataGrid
http://bea.stollnitz.com/blog/?p=426[^]

Alfanumeric custom sort
http://bea.stollnitz.com/blog/?p=24[^]
 
Share this answer
 
Comments
isi19 27-Jul-12 6:06am    
is there a way for me to sort it in Sql query?
Kenneth Haugland 27-Jul-12 6:13am    
You could do it like Prasad_Kulkarni suggested too.

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