Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i create table name "clstbl":
column name:
cls_id varchar(10)
cls_name varchar(20)

when i input 20 data in this table and see data:
cls_id is display like:
1
10
11
12
13
14
.
.
.
2
20
3
4
5
6
7
8
8
9

how to solve it
number is in order ...

i use sql server 2008 RC2
Posted

1 solution

Simplest solution is: don't use string based ID values to hold numeric values - use an int instead.

When you order anything string based, the ordering sequence is done by a character-byt-character comparison of the strings - in this scheme "19" comes before "2" because the character '1' comes before the character '2', and so on.

You can re-order strings to "work" in two ways:
1) Order the values converted to integers.
2) Store your values complete with leading zeros so they are all the same length.

But storing integers as integers is a much, much better idea!
 
Share this answer
 
Comments
priyanshbhaliya 9-Nov-13 13:42pm    
thanks
OriginalGriff 9-Nov-13 13:43pm    
You're welcome!

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