If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Selecting last 3 characters.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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.
Reply With Quote
  #2 (permalink)  
Old
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 12,554
select right(YourValue, 3)
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
www.LobsterShot.blogspot.com
Reply With Quote
  #3 (permalink)  
Old
Window Washer
 
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.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Posts: 164
Quote:
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.
Reply With Quote
  #5 (permalink)  
Old
Window Washer
 
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.
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Posts: 164
Quote:
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.
Reply With Quote
  #7 (permalink)  
Old
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 12,554
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
Reply With Quote
  #8 (permalink)  
Old
Window Washer
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On