Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
3.40/5 (3 votes)
See more:
Hello sql developers ,


I want to sort the number

1. It may contain zero or multiple decimal point e.g. 1 or 1.0.1

2. number may be like 00001 Note here we may trim 0000 to make it to 1

Column Data type is varchar(50)

eg.

1.
1.2
1.2.1
1.2.3
1.2.3.1
2.
00003 here we may trim 0000 to make it to 3
5.
7
100

the above one is just example of sorting that i want to do.

how shpuld i write query or function to do above sorting


Help is needed

Regards

Nitin
Posted
Updated 23-Dec-13 19:56pm
v3
Comments
Sergey Alexandrovich Kryukov 24-Dec-13 1:26am    
Numbers don't have decimal points; only string representing numbers may have them. Can you see the difference?
—SA
patil.nitin8358 24-Dec-13 1:37am    
i already mentioned datatype as varchar so dont go on title
Sergey Alexandrovich Kryukov 24-Dec-13 1:40am    
Let me go to any point I can see. You can change your title, for your own benefit.
—SA
patil.nitin8358 24-Dec-13 1:57am    
now i have changed question title as per ur suggestion.
Christian Graus 24-Dec-13 1:58am    
Not sure of the drama, your question was clear to at least two people and has been answered.

SA is right, numbers do not have more than one decimal. RK is right, for clarity, the answer he's referring to, is the one that casts your values to the heirarchyid[^] type.

SQL
select * from yourtable ORDER BY CAST('/' + yourVersionNumber + '/' AS hierarchyid)
 
Share this answer
 
Comments
Maciej Los 24-Dec-13 2:01am    
+5
 
Share this answer
 
Comments
Christian Graus 24-Dec-13 1:57am    
I upvoted this because it was correct, I did not know the answer, I just copied it for clarity and so the answer is here, even if it disappears there. I do suggest you both explain your answer, and provide your link, if you have one.
[no name] 24-Dec-13 3:16am    
Thanks .....Sir..
Maciej Los 24-Dec-13 2:01am    
+5
[no name] 24-Dec-13 3:16am    
Thanks .....Sir

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