You must Sign In to post a response.
  • Category: SQL Server

    How 101 less than 2 ?

    why 101 less than 2 in varchar field.(101 come first in ascending order before 2)please explain.........................
  • #765971
    if the data base field is varchar then it arrange with 1,2,3 like that, so the all the values start from 1 will soft first and then it takes the values start from 2 and finally all alphabets
    so to resolve your error you need to use CONVERT method (which is inbuilt in sql)
    see below snippet

    SELECT * FROM table1 ORDER BY convert('column1', decimal) ;

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765972
    Hi

    can you explain more. I canot get your words what you saying.

    Ascending issue means in your database records check your datatype

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765973
    i want to know the reason of this sequence
    1
    101
    10101
    1010101
    1010102
    1010103
    1010104
    10102
    1010201
    1010202
    1010203
    1010204
    102
    2
    201

  • #765982
    There are many ways to sorting. Numerical, String, etc..
    If you sort the numeric data it will come as follows
    1
    2
    101
    102
    201
    10101
    10102
    1010101
    1010102
    1010103
    1010104
    ....
    If you sort the string data data it will come as follows
    1
    101
    10101
    1010101
    1010102
    1010103
    1010104
    10102
    1010201
    ....
    For the string data type it will sort based on the numeric value. It will take as string value.
    All are based on you data type. Which data type you are using?. I hope you are using string data type.

    By Nathan
    Direction is important than speed

  • #765989
    Hi,

    Varchar field is nothing but a string format, so you are sorting result in string format, in string format the result should be 1, 101,10101.... then 2, 202,20202 etc... 3,303,.....

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765999
    Try using this:
    select columnABC from TableXYZ order by convert(numeric, columnABC) asc


Sign In to post your comments