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 2005 Forums
 Transact-SQL (2005)
 Varchar field order by not working correctly

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-09-18 : 15:26:36
What can i do to order by a varchar field.
Select picklisttext from picklisttable order by picklisttext

I am getting the data this way: After EA1 it should be EA2 but it is showing EA10:
******
EA1
EA10
EA11
EA12
EA13
EA14
EA15
EA16
EA17
EA18
EA19
EA2
EA21
EA22
EA23
EA24
EA25
EA26
EA27
EA29
******
Thank you very much for the helpful info.

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2009-09-18 : 18:30:43
It is sorting the data exactly as it is supposed to. The seeming discrepancy is that it is using a alphabetic ordering while you are assuming that it will recognize some of the characters as being numeric and impose a non-alphabetic ordering.

If it is possible to know what this string looks like (e.g., two letters followed by digits) it might be possible to impose the ordering that you require.

=======================================
Men build too many walls and not enough bridges. -Isaac Newton, philosopher and mathematician (1642-1727)
Go to Top of Page
   

- Advertisement -