what it should return max(name)?

  • hi,

    max function returns maximum no. from that table

    but if it is terms of string name what it should return?

    select max(name) from mytable??

  • it would return strings that start with the highest ascii value;

    i would expect it to return a string that starts with the letter "z" if it existed, and if there were more than one string that started with 'z', it would return the longer string that has the highest starting letters.

    for example, on my SLQ2008 instance, i have 3 strings that all match the same beginning chars:

    xp_ora2ms_exec2

    xp_ora2ms_exec2_ex

    xp_ora2ms_versioninfo2

    the max ends p being xp_ora2ms_versioninfo2, because at the 11th character for comparison, the letter "v" has a higher ascii value than "e"

    select MAX(name) from sys.objects

    select name from sys.objects where LEFT(name,2) = 'xp'

    select MAX(name) from sys.objects where name not like '%version%'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you so much

  • ashuthinks (1/19/2012)


    max function returns maximum no. from that table

    Close but not exactly what it does, if we define the function as max(expression) then the max() function returns the maximum value in the expression - no matter the data type.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

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

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