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

    Selecting last 3 characters.

    I want to select the last 3 characters from a field that have different character lenghts. How would you be able to do this.

    For example:
    pfw510s9055
    70125033
    efw674s8002

    I only want the last 3 characte from each of these items.


    Any help would be appreciated.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,569
    select right(YourValue, 3)
    If it's not practically useful, then it's practically useless.

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

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    SELECT RIGHT('pfw510s9055',3)
    SELECT RIGHT('70125033',3)
    SELECT RIGHT('efw674s8002',3)

    EDIT: eek-gadz...I've been [sniped]
    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.

  4. #4
    Join Date
    Jan 2004
    Posts
    164
    Originally posted by Brett Kaiser
    SELECT RIGHT('pfw510s9055',3)
    SELECT RIGHT('70125033',3)
    SELECT RIGHT('efw674s8002',3)

    EDIT: eek-gadz...I've been [sniped]

    Thanks fro the suggestion, but I am still running into some problem. You see, I am trying to only look at the last three characters of these product numbers, but there is thousands of different product #'s to insert the way it's displayed up above.

    I also tryed slect right(item_code, 3) and sinse not all items are the same lenght, some records return with blanck spaces and no characters because that item is shorter than others.

    Ultimately, I want ti to go to the end of each item and select the last three characters, whether the lenght of the item may be 15 characters or 7 characters.

    Thanks again, and like before all the help is appreciated.

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Not sure I totaly follow what your doing

    DECLARE @x varchar(20)
    SELECT @x = 'pfw510s9055 '
    SELECT '"'+@x+'"'

    SELECT RIGHT(RTRIM(@x),3)
    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.

  6. #6
    Join Date
    Jan 2004
    Posts
    164
    Originally posted by Brett Kaiser
    Not sure I totaly follow what your doing

    DECLARE @x varchar(20)
    SELECT @x = 'pfw510s9055 '
    SELECT '"'+@x+'"'

    SELECT RIGHT(RTRIM(@x),3)

    Sorry if I was not too clear. The good new is that what you sent me did work. All i had to use was:

    RIGHT(RTRIM(item_code),3)

    from the code above. That left me with the 3 last characters from field 'item_code'.

    Thanks once again on your help.

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,569
    Sniped me back!

    Damn you, Kaiser! I spent HOURS researching that reply!
    If it's not practically useful, then it's practically useless.

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

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Yeah right....
    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
  •