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
 SQL Server Development (2000)
 Substring Parse

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2005-10-07 : 10:58:11
Guys

I have a column populated with the values like

S_CONTROLTYPESLOV_ID
S_COUNTGROUPLOV_HIST_IID

I am trying to use substring to give me the string between first '_' and last '_' but so far been unsuccessful

Column Result
___________________________________________________
S_CONTROLTYPESLOV_ID CONTROLTYPESLOV
S_COUNTGROUPLOV_HIST_IID COUNTGROUPLOV_HIST

Do guys have any suggestions to do this

Thanks

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2005-10-07 : 11:08:03
Try this:

DECLARE @delim CHAR(1)
SET @delim = '_'

SELECT
SUBSTRING(t.MyField, CHARINDEX(@delim, t.MyField) + 1, LEN(a) - (CHARINDEX(@delim, t.MyField) + CHARINDEX(@delim, REVERSE(t.MyField))))
FROM
dbo.MyTable AS t


Mark
Go to Top of Page
   

- Advertisement -