February 7, 2012 at 12:42 am
I have a table one of it column is Varchar(20), it stores numerics, when using the Max() function it is limited to 5 character, that means it consider 99999 larger than 111111. so does anybody knows how to overcome this?
Regards
February 7, 2012 at 2:00 am
It's not that max is limited to 5 characters, it's that it is doing a string comparison (the column is varchar), and in string sorting, z is greater than aaa, similarly 9 is greater than 111
If you need them to sort as numbers for the max, then the column needs converting to numeric, or you need to cast to a numeric data type before taking the max.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply