sorting issue

  • 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]

  • Try sorting using the numeric part only:

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

    -- Gianluca Sartori

  • 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]

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

    -- Gianluca Sartori

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

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