IS IT POSSIBLE

  • Is it possible to sort a field which is a string and i m storing data

    ie.1,2,3,10,4,11 . I want result of a query to be like

    1

    2

    3

    4

    10

    11

    it is possible to write a query for this as data type is char or varchar so if i use order by clause i will get the result in this order 1,10,11,2,3,4

     

  • Try

     

    ORDER BY

    CAST(column AS varchar(10))

  • Probably wanted

    ORDER BY

    CAST(Column AS int)

    or

    ORDER BY

    CONVERT(int,Column)

    If there is nonnumeric data in the column

    the ISNUMERIC function might be handy.

    /rockmoose


    You must unlearn what You have learnt

  • Thanks u all for solving my problem

  • simplest way is

    ORDER BY RIGHT('0000000000'+COLUMN,10)

  • How about,

    Order by len(COLUMN),Column

     

     

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply