Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 substring

Author  Topic 

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-12-24 : 12:30:00
Hi.I have a coulmn with these valuse:

SANYO SCP-5300 L-ION 950mAh
SANYO SCP-5300 LI-ION 1400mAh
MOTOROLA V66 MB-C23 600mAh/BLU
MOTOROLA T720 MLC-3 1.2Ah/SLV
NEXTEL i95cl LN-KLM 1.4Ah/SLVR
NEXTEL i530 PLK-POL 1400mAh
.
.
.
.


how can I get the second part from the end of them.I mean I need these results:

L-ION
LI-ION
MB-C23
MLC-3
LN-KLM
PLK-POL
.
thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-24 : 13:00:48
Select substring (Column,charindex(' ',Column,10)+1,(charindex(' ',Column,16)- Charindex(' ',Column,10))) from table
Go to Top of Page

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-12-24 : 13:22:30
thank u so much :)
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-24 : 13:23:44
Welcome. Merry Christmas
Go to Top of Page

Kumar_Anil
Yak Posting Veteran

68 Posts

Posted - 2008-12-24 : 18:30:35
Hello !!!

I ran into a similar situation a while ago & here is what I had back then. This is bit yucky but this is what I used & it never failed me so far.

regards,
Anil Kumar.


select left(
substring(substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1),
charindex(' ',substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1), 0)+1,
len(substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1)) -
charindex( ' ', substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1),0)+1),
charindex(' ', substring(substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1),
charindex(' ',substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1), 0)+1,
len(substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1)) -
charindex( ' ', substring (Column, charindex(' ', Column, 0)+1, len(Column) - charindex(' ', Column, 0)+1),0)+1)))

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-25 : 02:33:32
quote:
Originally posted by a.ashabi

Hi.I have a coulmn with these valuse:

SANYO SCP-5300 L-ION 950mAh
SANYO SCP-5300 LI-ION 1400mAh
MOTOROLA V66 MB-C23 600mAh/BLU
MOTOROLA T720 MLC-3 1.2Ah/SLV
NEXTEL i95cl LN-KLM 1.4Ah/SLVR
NEXTEL i530 PLK-POL 1400mAh
.
.
.
.


how can I get the second part from the end of them.I mean I need these results:

L-ION
LI-ION
MB-C23
MLC-3
LN-KLM
PLK-POL
.
thanks


if format is consistent with always 4 words you can use this

SELECT PARSENAME(REPLACE(column,' ','.'),2) FROM Table
Go to Top of Page
   

- Advertisement -