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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 extracting data from a field

Author  Topic 

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-06-23 : 08:04:08
I am thinking this should be a simple solution. I just can't figure it out.

I have a field named [Name-Chem]
Example data within this field...

AWS A5.23-97 for ENi1K
AWS A5.23-97 for EM2
EN 12070 for CrMo2

I need to extract only the last section of the data.
Example

ENi1K
EM2
CrMo2

I was dabbling with the CHARINDEX to try and create a start postition. I was unsuccessful.

Thanks for your help!!


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-06-23 : 08:29:57
declare @s varchar(100)

select @s = 'AWS A5.23-97 for ENi1K'

select substring(@s, charindex(' for ', @s) + 5, len(@s))



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-06-23 : 08:39:45
thanks this worked great!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-23 : 08:45:22
More general

declare @s varchar(100)
select @s = 'AWS A5.23-97 for ENi1K'
select right(@s,charindex(' ', reverse(@s))-1)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -