June 29, 2010 at 1:53 am
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]
June 29, 2010 at 2:08 am
Try sorting using the numeric part only:
select top 1 @num = num from table order by right(num,len(num)-4) desc
-- Gianluca Sartori
June 29, 2010 at 2:42 am
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]
June 29, 2010 at 4:01 am
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
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy