Help With Alphanumeric sorting??

I have a table with a column called ITEMNUM an example of the data in the column is:

P10
P20
P100
P30

Incrementing by 10's
If I do a select ITEMNUM from INVENTORY order by ITEMNUM

I get:
P10
P100
P20
P30

Is there a way that I can have it to where it will retun like this:

P10
P20
P30
P100

Thanks in advance

Comments

  • select itemnum
    from inventory
    order by left(itemnum,1), cast(right(itemnum,len(itemnum)-1) as int)



    : I have a table with a column called ITEMNUM an example of the data in the column is:
    :
    : P10
    : P20
    : P100
    : P30
    :
    : Incrementing by 10's
    : If I do a select ITEMNUM from INVENTORY order by ITEMNUM
    :
    : I get:
    : P10
    : P100
    : P20
    : P30
    :
    : Is there a way that I can have it to where it will retun like this:
    :
    : P10
    : P20
    : P30
    : P100
    :
    : Thanks in advance
    :

  • : select itemnum
    : from inventory
    : order by left(itemnum,1), cast(right(itemnum,len(itemnum)-1) as int)
    :
    :
    :
    : : I have a table with a column called ITEMNUM an example of the data in the column is:
    : :
    : : P10
    : : P20
    : : P100
    : : P30
    : :
    : : Incrementing by 10's
    : : If I do a select ITEMNUM from INVENTORY order by ITEMNUM
    : :
    : : I get:
    : : P10
    : : P100
    : : P20
    : : P30
    : :
    : : Is there a way that I can have it to where it will retun like this:
    : :
    : : P10
    : : P20
    : : P30
    : : P100
    : :
    : : Thanks in advance

    Or just pad your numbers:

    P010
    P020
    P030
    P100


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories