how to select last two characters of a string

  • Hi

    I need to select last two characters of a field like the field has codes

    Ex:

    abcDE

    cccDE

    bbbDE

    and i want to get the codes that has the last two characters=DE

    Thanks

  • want_to_know (4/17/2008)


    Hi

    I need to select last two characters of a field like the field has codes

    Ex:

    abcDE

    cccDE

    bbbDE

    and i want to get the codes that has the last two characters=DE

    Thanks

    declare @STR varchar(20)

    set @STR - 'abcDE'

    select right(@str,2)

    That help?

    😎

  • Yes it did

    Thank you so much Lynn

    Have a wonderful day

  • Just to make sure you get good data:

    RIGHT(RTRIM(LTRIM(column_name)), 2)

    With the previous example, you could have gotten a space instead of the desired two characters.

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

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