MAX

  • 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

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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