Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    164

    Unanswered: Selecting the last 3 characters from a string

    Hello Everyone,

    I am trying to select the last 3 characters from a string. I am running into problems because the sting that I am selecting from are not the same amout of characters.

    For example:

    Item

    abc145264
    efg1254
    wqx21456


    How would I be able to select the last three characters from a list that could have more than 50 variations on the number of characters.

    I tryed right(item, 3) but that does not work because all the lenghts are different. Any ideas?

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    substring (reverse(field), 1, 3)


    EDIT: If you want them in original order:

    reverse (substring (reverse(field), 1, 3))

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The RIGHT() function should work for you.
    What is the datatype of ITEM? Post some sample data, and the results you get from the RIGHT(Item, 3) function.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    I'm not sure I understand..

    Code:
    DECLARE @t table (Col1 varchar(50))
    
    INSERT INTO @t (Col1)
    SELECT 'abc145264' UNION ALL
    SELECT 'efg1254' UNION ALL
    SELECT 'wqx21456'
    
    SELECT RIGHT(Col1,3) FROM @t
    Isn't this what you want?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •