sorting issue

  • Ahmad Osama

    SSCertifiable

    Points: 7676

    I have a column num nvarchar(30) ... with values of the form 'ABC-0000001' which were to incremented automatically. The code I wrote works correctly until the value reaches to 'ABC-10000000'.

    Am using ..

    select top 1 @num=num from table order by num desc

    always gives 'ABC-9999999' also max(num) gives the same...

    any ideas

    Regards,
    [font="Verdana"]Sqlfrenzy[/font]

  • spaghettidba

    SSC Guru

    Points: 105661

    Try sorting using the numeric part only:

    select top 1 @num = num from table order by right(num,len(num)-4) desc

  • Ahmad Osama

    SSCertifiable

    Points: 7676

    Gianluca Sartori (6/29/2010)


    Try sorting using the numeric part only:

    works with little modification

    select top 1 @num = num from table order by cast(right(num,len(num)-4) as int) desc

    Regards,
    [font="Verdana"]Sqlfrenzy[/font]

  • spaghettidba

    SSC Guru

    Points: 105661

    Ooops! You're right, sorry for the bad advice.

Viewing 4 posts - 1 through 4 (of 4 total)

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